Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class mysql_db {
- private static $instance;
- public static $connection;
- public function __construct($host=null, $user=null, $password=null, $db=null) {
- if(!self::$instance && !$host) {
- throw new Exception("Missing Database..!!!");
- }
- self::$connection = mysqli_connect($host,$user,$password,$db);
- }
- public function __destruct() {
- mysqli_close(self::$connection);
- }
- public function getData($table_name) {
- $rs= mysqli_query(self::$connection,"SELECT * FROM $table_name");
- return mysqli_fetch_all($rs,MYSQLI_ASSOC);
- }
- public function getOne($table_name) {
- $rss= mysqli_query(self::$connection,"SELECT * FROM $table_name LIMIT 1");
- return mysqli_fetch_assoc($rss);
- }
- public function find($table_name,$sn,$val) {
- $rq= mysqli_query(self::$connection,"SELECT * FROM $table_name WHERE $sn='$val'");
- return mysqli_fetch_all($rq,MYSQLI_ASSOC);
- }
- **// I AM GETTING ERROR FROM THESE LINES**
- //-> public function __call($table_name,$sn) {
- //-> //var_dump("SELECT * FROM $table_name where sn='1'");
- //-> $rt= mysqli_query(self::$connection,"SELECT * FROM $table_name
- WHERE '$sn'")or die(mysqli_error()) ;
- //-> return mysqli_fetch_all($rt,MYSQLI_ASSOC);
- }
- public static function getInstance() {
- try {
- if(!self::$instance) {
- self::$instance=new static('localhost','root','','xam');
- }
- } catch(Exception $e) {
- echo 'Caught Error: ', $e->getMessage(), "n";
- }
- return self::$instance;
- }
- }
- $h= mysql_db::getInstance();
- var_dump($h->name("1"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement