4 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
<?php//define a database classclass DB { //the static connection. //This is available to all instances of the class as the same connection. private static $_conn; //store the result available to all methods private $result; //store the last query available to all methods private $lastQuery; //static connection function. connects to the database and stores that connection statically. public static function connect($host, $user, $pass, $db){ self::$_conn = mysqli_connect($host, $user, $pass, $db); } //standard function for doing queries. uses the static connnection property. public function query($query){ $this->lastQuery = $query; $this->result = mysqli_query(self::$_conn, $query); //process result, return expected output. }}//create connection to the database, this connection will be used in all instances of DB classDB: :connect('local', 'DB_USER', 'DB_PASS');//create instance to query$test = new DB; //do query$test->query("SELECT * FROM TABLE");//test functionfunction foo(){ //create instance to use in this function $bar = new DB; //do query $bar->query("SELECT * FROM OTHER_TABLE"); //return results return $bar->fetchArray();}

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
$db
get_records
$records = $pagination->get_records("SELECT * FROM `table`", $db);
public function get_records($q, $db) {

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
添加回答
舉報(bào)