我正在检查此代码中的两个表的计数。这两个查询都是单独工作,但是这样写它们总会出错。
<?php
require 'db/userWrite.php';
error_reporting(E_ALL);
ini_set('display_errors', '1');
$today = new DateTime("now");
$last = new DateTime("20.03.14");
$fquery = "SELECT count(*) as female FROM female_athletes";
$fresult = $db->prepare($fquery);
$fresult->execute();
$fresult->bind_result($female);
$fresult->fetch();
var_dump($fresult);
$mquery = "SELECT count(*) as male FROM male_athletes";
$m = $db->prepare($mquery);
$m->execute();
$m->bind_result($male);
$m->fetch();
结果
object(mysqli_stmt)#4(10){[“affected_rows”] =&gt; INT(-1) [ “INSERT_ID”] =&GT; int(0)[“num_rows”] =&gt; int(0)[“param_count”] =&gt; INT(0) [ “场计数”] =&GT; int(1)[“errno”] =&gt; int(0)[“error”] =&gt; string(0)“” [ “error_list”] =&GT; array(0){} [“sqlstate”] =&gt; string(5)“00000” [ “ID”] =&GT; int(1)}
注意:未定义的变量:m in / home / .... on line
致命错误:在/ home / ...行上的非对象上调用成员函数execute()