0
I have a problem to pass the consultation (this->Query($sql))
and the rest to mysqli
. I don’t know how to proceed
MISTAKES:
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);
}
}
?>
As 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();
?>
It would be interesting to have some of the mistakes that happen so that we can get from there. So it will be amis easy to understand each mistake and bring a solution.
– Erlon Charles
You are right, here the errors that happen 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 @Erloncharles
– Weliton
Put the code as you call this class.
– rray
@rray

<?php
 # configuration for database
 $_config['database']['hostname'] = "localhost";
 $_config['database']['username'] = "root";
 $_config['database']['password'] = "xxx";
 $_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();
?>
– Weliton
@rray, used this way in php5, here locally, no problem, what I wanted to put in a server here on the other side that used php7 ai needed to migrate mysql strings to mysqli, that’s where the problems occur, in the errors the connection seems ok only the query that of the error, but I also don’t know how to confirm
– Weliton
Do the following: change:
$this->query = mysqli_query($this->link, $sql);
for$this->query = mysqli_query($this->link, $sql) or die(mysqli_error($this->link));
see if another error message appears.– rray
@rray now leaves the screen blank without error, in apache log continues mysqli_query() expects Parameter 1 to be mysqli, null Given in
– Weliton
So the connection is not valid, check this, see the return of
connect()
– rray
@rray how? Return connect(); ? so gave error. do not know much ><
– Weliton