I'm having a problem passing the query (this->Query($sql))
and the others to mysqli
. I do not know how to proceed
ERRORS:
PHP Warning: mysqli_query () expects parameter 1 to be mysqli, null given in /var/www/html/manager/include/class.mysqldb.php on line 23 PHP Warning: mysqli_fetch_object () expects parameter 1 to be mysqli_result, null given in /var/www/html/manager/include/class.mysqldb.php on line 27 PHP Warning: mysqli_num_rows () expects parameter 1 to be mysqli_result, null given in /var/www/html/manager/include/class.mysqldb.php on line 31
<?php
class mysqldb {
var $link;
var $result;
function connect($config) {
$this->link = mysqli_connect($config['hostname'], $config['username'], $config['password'], $config['database']);
if ($this->link) {
mysqli_query($this->link, "SET NAMES 'utf-8'");
return true;
}
$this->show_error(mysqli_error($this->link), "connect()");
return false;
}
function selectdb($database) {
if ($this->link) {
mysqli_select_db($this->link, $database);
return true;
}
$this->show_error("Not connect the database before", "selectdb($database)");
return false;
}
function query($sql) {
$this->query = mysqli_query($this->link, $sql);
return $this->query;
}
function fetch() {
$result = mysqli_fetch_object($this->query);
return $result;
}
function num_rows() {
return mysqli_num_rows($this->query);
}
function show_error($errmsg, $func) {
echo "<b><font color=red>" . $func . "</font></b> : " . $errmsg . "<BR>\n";
exit(1);
}
}
?>
How do I call the class
<?php
# configuration for database
$_config['database']['hostname'] = "localhost";
$_config['database']['username'] = "root";
$_config['database']['password'] = "senha";
$_config['database']['database'] = "banco";
# connect the database server
$link = new mysqldb();
$link->connect($_config['database']);
$link->selectdb($_config['database']['database']);
$link->query("SET NAMES 'utf8'");
@session_start();
? >