It worked fine with the mysql in there but I really wanted to convert it to mysqli
If someone could guide me in the right direction here, I'd appreciate. I've researched the functions that are giving the problems but they seem correct to me but obviously I'm missing something.
The errors I'm getting are the following:
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /home/html/ooconn.php on line 16
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/html/ooconn.php on line 42
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/html/ooconn.php on line 44
PHP
class DB{
private $host = 'stuff';
private $un = 'stuff';
private $pw = 'stuff';
private $db = 'stuff';
private static $_link;
public function __construct($db=null){
if(!is_null($db)){
$this->db = $db;
}
$this->_link = mysqli_connect($this->host,$this->un,$this->pw);
16--> mysqli_select_db($this->db,$this->_link);
}
public function __destruct(){
mysqli_close($this->_link);
}
public function getInstance($db = null){
if(is_null(self::$_link)){
self::$_link = new DB($db);
}
return self::$_link;
}
public function prepare($var){
if(is_array($var)){
foreach($var as $key=>$val){
$clean[$key] = mysqli_real_escape_string($val,$this->_link);
}
} else {
$clean = mysqli_real_escape_string($val,$this->_link);
}
return $clean;
}
public function query($sql){
42 -> $result = mysqli_query($sql,$this->_link);
$i=0;
44 ->while($array = mysqli_fetch_assoc($result)){
foreach($array as $key=>$val){
$return[$i][$key] = $val;
}
$i++;
}
return $return;
}
}
HTML
// get instance
include('ooconn.php');
$db = DB::getInstance();
//query
$result = $db->query("SELECT * FROM `members`");
print_r($result);

New Topic/Question
Reply




MultiQuote



|