我正在尝试使用mysqli函数,但是我收到了这个错误:
Fatal error: Call to undefined method mysqli::num_rows() in C:\AppServ\www\edu\files\header.php on line 19
我尝试转到php.ini
并从;
移除extension=php_mysqli.dll
我发现它已被删除
我试图重启appachi; 连接文件:
// db username
define("USERNAME","root");
// db password
define("PASSWORD","root");
// db servername
define("SERVERNAME","localhost");
// db name
define("NAME","edu");
//connect to db
$mysqli = new mysqli(SERVERNAME,USERNAME,PASSWORD,NAME);
if ($mysqli->connect_errno) {
echo $cannot_connect;
}
//select db encoding
$mysqli->set_charset('utf8');
在文件中调用函数:
$sql = $mysqli->query("SELECT VALUE FROM SITE_CONFIG WHERE CONF='KEYWORDS'");
if (!$sql) {
echo "Failed to run query: (" . $mysqli->errno . ") " . $mysqli->error;
}
if($mysqli->num_rows($sql) > 0){
while($rs = $sql->fetch_assoc()){
$keyw = $rs['VALUE'];
}
}else{
$keyw = $no_data;
}
注意:我包含了connection.php
答案 0 :(得分:0)
尝试:
$sql = $mysqli->query("SELECT VALUE FROM SITE_CONFIG WHERE CONF='KEYWORDS'");
if (!$sql) {
echo "Failed to run query: (" . $mysqli->errno . ") " . $mysqli->error;
} else {
if($sql->num_rows > 0){// here must be $sql , not $mysqli
while($rs = $sql->fetch_assoc()){
echo $rs['VALUE'];
}
} else{
echo "No data";
}
}