MySQLi Un-prepared-d
MySQLi Un-prepare-d
我正在将旧的 mysql_* 查询转换为 mysqli,但我遇到了一个令人沮丧的问题
$st = $this->Sql->prepare("INSERT INTO tblPlayerOnline (SteamID,PlayerName,IPAddress,ConnectedDate) VALUES (?, ?, ?, ?)") or die($this->Sql->error);
/* 225 */ $st->bind_param("i", $SteamID);
$st->bind_param("ssi", $PlayerName, $IPAddress, $TimeNow);
$st->execute();
Fatal error: Call to a member function bind_param() on a non-object in /home/vanrust/public_html/rework/class/Players.class.php on line 225
但是当我转储 $this->Sql
时,我得到 object(mysqli)#2 (19) { bla bla
所以不确定这个错误告诉我什么。
转储 $this->Sql
http://pastebin.com/gdKAgT4D
感谢任何指导!
PS到处看-.-
看起来 $st
是空的,意味着语句准备失败。
试着看看是什么原因造成的:
if (!$st) {
echo "Prepare failed: (" . $this->Sql->errno . ") " . $this->Sql->error;
}
当 prepare
语句失败并且没有返回任何 mysqli_prepare
对象时,您的查询中很可能有错误.. 或者更糟。
出于调试目的,您可以使用 mysqli_report(MYSQLI_REPORT_ALL)
函数(它是 mysqli_driver->report_mode
的别名)。这可以为您提供更多信息 prepare
失败的原因,并有助于调试。
将以下内容放在代码的开头
mysqli_report(MYSQLI_REPORT_ALL);
//Or if you just want an exception when Mysqli has an error?
//Set the reporting level to
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
除此之外,我认为总是假设返回 mysql_prepare
对象是非常冒险的。使用前请先确认:
if ($stmt = $this->Sql->prepare(....)) {
//Yep, we can now start binding parameters
} else {
//Noooooo.. got error?
}
好吧,这让我沮丧了一段时间,但我发现答案一直摆在我面前 $this->Sql->stat
- 奇怪的是,400 张开放的桌子似乎是一个相当不错的偶数,但这显然是一个最大值。
我回溯了我的代码并开始向所有内容添加 $st->close()
,这为我解决了这个问题。
所以吸取教训;完成后关闭它
感谢大家的帮助
我正在将旧的 mysql_* 查询转换为 mysqli,但我遇到了一个令人沮丧的问题
$st = $this->Sql->prepare("INSERT INTO tblPlayerOnline (SteamID,PlayerName,IPAddress,ConnectedDate) VALUES (?, ?, ?, ?)") or die($this->Sql->error);
/* 225 */ $st->bind_param("i", $SteamID);
$st->bind_param("ssi", $PlayerName, $IPAddress, $TimeNow);
$st->execute();
Fatal error: Call to a member function bind_param() on a non-object in /home/vanrust/public_html/rework/class/Players.class.php on line 225
但是当我转储 $this->Sql
时,我得到 object(mysqli)#2 (19) { bla bla
所以不确定这个错误告诉我什么。
转储 $this->Sql
http://pastebin.com/gdKAgT4D
感谢任何指导!
PS到处看-.-
看起来 $st
是空的,意味着语句准备失败。
试着看看是什么原因造成的:
if (!$st) {
echo "Prepare failed: (" . $this->Sql->errno . ") " . $this->Sql->error;
}
当 prepare
语句失败并且没有返回任何 mysqli_prepare
对象时,您的查询中很可能有错误.. 或者更糟。
出于调试目的,您可以使用 mysqli_report(MYSQLI_REPORT_ALL)
函数(它是 mysqli_driver->report_mode
的别名)。这可以为您提供更多信息 prepare
失败的原因,并有助于调试。
将以下内容放在代码的开头
mysqli_report(MYSQLI_REPORT_ALL);
//Or if you just want an exception when Mysqli has an error?
//Set the reporting level to
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
除此之外,我认为总是假设返回 mysql_prepare
对象是非常冒险的。使用前请先确认:
if ($stmt = $this->Sql->prepare(....)) {
//Yep, we can now start binding parameters
} else {
//Noooooo.. got error?
}
好吧,这让我沮丧了一段时间,但我发现答案一直摆在我面前 $this->Sql->stat
- 奇怪的是,400 张开放的桌子似乎是一个相当不错的偶数,但这显然是一个最大值。
我回溯了我的代码并开始向所有内容添加 $st->close()
,这为我解决了这个问题。
所以吸取教训;完成后关闭它
感谢大家的帮助