Guest User

Untitled

a guest
Dec 12th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. class database{
  2. protected $databaseLink = null;
  3. function __construct($dbInfo){
  4.  
  5. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  6. $this->database = $dbInfo['host'];
  7. $this->mysql_user = $dbInfo['user'];
  8. $this->mysql_pass = $dbInfo['pass'];
  9. $this->mysql_db = $dbInfo['dbname'];
  10. $this->openConnection();
  11. return $this->get_link();
  12. }
  13. function openConnection(){
  14. try {
  15. $this->databaseLink = new mysqli($this->database , $this->mysql_user, $this->mysql_pass, $this->mysql_db);
  16. $status = $this->databaseLink->set_charset("utf8");
  17. if ($status === false) {
  18. //throw new Database_Exception(self::$dbInstance->error, self::$dbInstance->errno);
  19. }
  20. } catch (mysqli_sql_exception $e) {
  21. if (mysqli_connect_error()) {
  22. die('Connect Error (' . mysqli_connect_errno() . ') '
  23. . mysqli_connect_error());
  24. }
  25. //echo $e->__toString();
  26. }
  27. }
  28. function get_link(){
  29. return $this->databaseLink;
  30. }
  31. }
  32. $db = new database($dbInfo);
  33. $query = "SELECT prod_id as id, diction, name as display_name FROM htbl_products ORDER by id LIMIT 10";
  34.  
  35. $result = $db->query($query); //Fatal error: Call to undefined method database::query()
  36.  
  37. try {
  38. $db = new mysqli($dbInfo['host'], $dbInfo['user'], $dbInfo['pass'], $dbInfo['dbname']);
  39. $db->set_charset("utf8");
  40. } catch (mysqli_sql_exception $e) {
  41.  
  42. if (mysqli_connect_error()) {
  43. die('Connect Error (' . mysqli_connect_errno() . ') '
  44. . mysqli_connect_error());
  45. }
  46. //echo $e->__toString();
  47. }
Add Comment
Please, Sign In to add comment