0
我想从我的数据库使用PDO选择数据。然而,每当我运行查询PDO“rowCount()”返回0受影响的行。当我在Navicat中运行相同的查询时,我得到了返回的相应行。PDO/SQL返回0,在Navicat工作
我的代码:
$select = $dbh->prepare("SELECT columnName FROM tblName WHERE columName2 = :val1 AND `value` = :val2");
$select->execute(
array(
":val1" => "data1",
":val2" => "data2"
)
);
我配置PDO抛出错误,我的代码在try/catch块运行。尝试部分被执行到最后,没有抛出异常。
我想实现的目标:获取适当的行并插入到新表中。
关于我的问题可能出在哪里的任何想法?
编辑:
try {
$dbh->beginTransaction();//drop/create table
if($dbh->exec("DROP TABLE IF EXISTS tblName") === false)
{
$dbh->rollback();
exit($dbh->errInfo());
}
if($dbh->exec("CREATE TABLE tblName (id bigint);") === false)
{
$dbh->rollback();
exit($dbh->errInfo());
}
$dbh->commit();//save table
$dbh->beginTransaction();//insert transaction
$put = $dbh->prepare("INSERT INTO tblName (id) VALUES (:id)");
$bind = array(
":id" => null
);
$a = "string";
// $b = "[lang_es]string[/lang_es][lang_en]string[/lang_en]";
$select = $dbh->prepare("SELECT columnName FROM tblName WHERE columnName = :val1 ");
// AND `value` = :val2");
$select->bindValue(":val1", $a);
// $select->bindValue(":val2", $b);
$select->execute();
print_r($select);
while($row = $select->fetch(PDO::FETCH_ASSOC))
{
$bind[":id"] = $row["columName"];
$put->execute($bind);//inserts row
$put->closeCursor();//optional
}
$dbh->commit();//save changes to db
var_dump($dbh->errorInfo());
}
'var_dump($ select-> fetchAll());'show? – Lucas
@Lucas数组(大小= 0)空 – user3568224
你还没有指定数据库,也许你需要开始一个事务,或者你没有连接,或者查询有错误,试试'var_dump($ dbh-> errorInfo());'来阐明它。 – Lucas