PDO选择查询错误
我正在尝试使用 PDO::MySQL 运行这个简单的 SELECT 查询,但它不返回值,正如您从转储中看到的 $row 返回 false,这意味着存在错误。
数据库连接有效,因为我正在往数据库写入几行,
Sql 查询是正确的
有人能看到这段代码中的错误吗?如果可以的话,我真的很感激,因为这已经困扰了我几个小时
$statement = $DbConn->prepare("SELECT id FROM mineral_index WHERE typeID = :typeID AND systemID = :systemID");
$statement->bindParam('typeID', $this->typeID, PDO::PARAM_INT);
$statement->bindParam('systemID', $this->systemID, PDO::PARAM_INT);
$row = $statement->fetchObject();
echo "<p><pre>";
$statement->debugDumpParams();
var_dump($statement->errorInfo());
var_dump($this->typeID);
var_dump($this->systemID);
var_dump($row);
echo "</pre></p>";
了:
SQL: [76] SELECT id FROM mineral_index WHERE typeID = :typeID AND systemID = :systemID
Params: 2
Key: Name: [7] :typeID
paramno=-1
name=[7] ":typeID"
is_param=1
param_type=1
Key: Name: [9] :systemID
paramno=-1
name=[9] ":systemID"
is_param=1
param_type=1
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
int(35)
int(30000142)
bool(false)
I am trying to run this simple SELECT query using PDO::MySQL, but it does not return a value, as you can see from the dump $row returns false, which means there was an error.
The database connection works, as I'm writing to the database a few lines further down
Sql query is correct
Can someone see the bug in this code? If you can I'd really appreciate it, as this has been annoying me for hours
$statement = $DbConn->prepare("SELECT id FROM mineral_index WHERE typeID = :typeID AND systemID = :systemID");
$statement->bindParam('typeID', $this->typeID, PDO::PARAM_INT);
$statement->bindParam('systemID', $this->systemID, PDO::PARAM_INT);
$row = $statement->fetchObject();
echo "<p><pre>";
$statement->debugDumpParams();
var_dump($statement->errorInfo());
var_dump($this->typeID);
var_dump($this->systemID);
var_dump($row);
echo "</pre></p>";
dump:
SQL: [76] SELECT id FROM mineral_index WHERE typeID = :typeID AND systemID = :systemID
Params: 2
Key: Name: [7] :typeID
paramno=-1
name=[7] ":typeID"
is_param=1
param_type=1
Key: Name: [9] :systemID
paramno=-1
name=[9] ":systemID"
is_param=1
param_type=1
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
int(35)
int(30000142)
bool(false)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$语句->execute(); ????
$statement->execute(); ?????