Object Oriented mysqli connection function
PsychoCoder Recently a friend was having a hard time connecting using mysqli, so I showed an OO Experway of accomplishing the task with this code t Mod 100+Expand|Select|Wrap|Line Numbers P: 131 1. class db_connection extends mysqli 2. { 3. public function __construct($dbhost, $username, $password , $db) 4. { 5. parent::__construct($dbhost, $username, $password, $d b); 6. 7. if (mysqli_connect_error()) 8. { 9. die('Connection Error: (' . mysqli_connect_errno( ) . ') ' . mysqli_connect_error()); 10. } 11. } 12.} 13. 14.$db = new db_connection('localhost', 'username', 'password', 'db'); 15. 16.echo 'Success... ' . $db->mysqli_get_host_info($db) . "n"; 17. 18.$db->close();
Object oriented mysqli connection function

Object oriented mysqli connection function

  • 1.
    Object Oriented mysqliconnection function
  • 2.
    PsychoCoder Recently a friend was having a hard time connecting using mysqli, so I showed an OO Experway of accomplishing the task with this code t Mod 100+Expand|Select|Wrap|Line Numbers P: 131 1. class db_connection extends mysqli 2. { 3. public function __construct($dbhost, $username, $password , $db) 4. { 5. parent::__construct($dbhost, $username, $password, $d b); 6. 7. if (mysqli_connect_error()) 8. { 9. die('Connection Error: (' . mysqli_connect_errno( ) . ') ' . mysqli_connect_error()); 10. } 11. } 12.} 13. 14.$db = new db_connection('localhost', 'username', 'password', 'db'); 15. 16.echo 'Success... ' . $db->mysqli_get_host_info($db) . "n"; 17. 18.$db->close();