mysqli的对象不工作
问题描述:
我有这样一段代码:mysqli的对象不工作
$db = new mysqli("localhost", "user", "pw", "db");
$result = $db->query($db, "SELECT * FROM usertable");
$numrows = $db->num_rows;
print "There are $numrows people in usertable\n";
,并得到该错误消息:
PHP的警告:mysqli的查询::()预计参数1是字符串,对象给定
为什么这不起作用?
感谢您的帮助!
答
您正在使用OOP调用,所以你不需要有参数
内$db
参数同样的NUM_ROWS调用应该使用这样
的MYSQL_RESULT对象,这样做
$result = $db->query("SELECT * FROM usertable");
$numrows = $result->num_rows;
+0
工作过,谢谢! –
1. $ db-> query($ db,“SELECT * FROM usertable”);'应该是'$ db-> query(“SELECT * FROM usertable”);''db-> num_rows; '应该是'$ result-> num_rows;'。请仔细阅读文件。 –