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