我正在尝试PDO
连续执行两个单独的查询。但是,一次只能正确执行一个。无论哪个先出现,都是唯一正确查询数据库并返回任何值的。我尝试使用 var_dump 查看它们返回的内容,第二个 PDO 查询返回“boolean false”并且不包含任何信息。
这是我的代码:
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
// make and execute query for client information
$client_query = $db->prepare('SELECT * FROM clients WHERE id=:ID');
$client_query->execute(array('ID' => $client_id));
$client_result = $client_query->fetch(PDO::FETCH_ASSOC);
// set client information for captcha
$this->client_name = $client_result['name'];
$this->client_id = $client_result['id'];
$client_query->closeCursor();
// make and execute query for campaign information
$campaign_query = $db->prepare('SELECT * FROM campaigns WHERE id=:ID AND client_id=:CLIENT');
$campaign_query->execute(array('ID' => $campaign_id, 'CLIENT' => $client_id));
$campaign_result = $campaign_query->fetch(PDO::FETCH_OBJ);
// set campaign information for captcha
$this->campaign = $campaign_result;
如果我从第二个查询中删除参数,它们都会成功执行。我在这里做错了什么?谢谢!