在SELECTION语句的非对象上调用成员函数bind_param()

时间:2015-04-09 09:45:29

标签: php mysql

我使用以下代码段从学生表中选择行数。但它显示错误"致命错误:在非对象上调用成员函数bind_param()"。在我的桌子' stacyear'是VARCHAR,' courseid'是TINY INT。

$stmt = $mysqli->prepare("SELECT count (*) FROM students WHERE stacyear = ? and courseid = ?");
$stmt->bind_param('si', $acyear, $courseid); 
$stmt->execute();    
$stmt->store_result();
$stmt->bind_result($utype);
$stmt->fetch();

1 个答案:

答案 0 :(得分:2)

您不能在COUNT(*)之间留出空格。改为

$stmt = $mysqli->prepare("SELECT count(*) FROM students WHERE stacyear = ? and courseid = ?");