Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. class mysql_db {
  2. private static $instance;
  3. public static $connection;
  4.  
  5. public function __construct($host=null, $user=null, $password=null, $db=null) {
  6. if(!self::$instance && !$host) {
  7. throw new Exception("Missing Database..!!!");
  8. }
  9. self::$connection = mysqli_connect($host,$user,$password,$db);
  10. }
  11.  
  12. public function __destruct() {
  13. mysqli_close(self::$connection);
  14. }
  15.  
  16. public function getData($table_name) {
  17. $rs= mysqli_query(self::$connection,"SELECT * FROM $table_name");
  18. return mysqli_fetch_all($rs,MYSQLI_ASSOC);
  19. }
  20.  
  21. public function getOne($table_name) {
  22. $rss= mysqli_query(self::$connection,"SELECT * FROM $table_name LIMIT 1");
  23. return mysqli_fetch_assoc($rss);
  24. }
  25.  
  26. public function find($table_name,$sn,$val) {
  27. $rq= mysqli_query(self::$connection,"SELECT * FROM $table_name WHERE $sn='$val'");
  28. return mysqli_fetch_all($rq,MYSQLI_ASSOC);
  29. }
  30.  
  31.  
  32. **// I AM GETTING ERROR FROM THESE LINES**
  33.  
  34. //-> public function __call($table_name,$sn) {
  35. //-> //var_dump("SELECT * FROM $table_name where sn='1'");
  36. //-> $rt= mysqli_query(self::$connection,"SELECT * FROM $table_name
  37. WHERE '$sn'")or die(mysqli_error()) ;
  38. //-> return mysqli_fetch_all($rt,MYSQLI_ASSOC);
  39. }
  40.  
  41. public static function getInstance() {
  42. try {
  43. if(!self::$instance) {
  44. self::$instance=new static('localhost','root','','xam');
  45. }
  46. } catch(Exception $e) {
  47. echo 'Caught Error: ', $e->getMessage(), "n";
  48. }
  49. return self::$instance;
  50. }
  51. }
  52. $h= mysql_db::getInstance();
  53. var_dump($h->name("1"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement