这不是其他num_rows == 0帖子的副本,因为在此上下文中不需要store_result。请参阅:us3.php.net/manual/en/mysqli-stmt.get-result.php。只要在查询语句之后立即使用get_result,就不需要store_result。上面文档中的示例代码不使用store_result。
由于某种原因,此查询返回0行时应该为给定地址返回33行,该地址重复33次。我必须在某处找不到语法错误。有谁看到我在这里失踪了什么?
function createIfNew()
{
$this->logger->log(print_r($this,true));
$s = $this->db->prepare('SELECT * FROM mcdb2.addresses
WHERE
addresses_street1 = ?
AND addresses_street2 = ?
AND addresses_city = ?
AND addresses_state = ?
AND addresses_zip = ?');
$s->bind_param('ssssi',$this->addresses_street1,$this->addresses_street2,$this->addresses_city,$this->addresses_state,$this->addresses_zip);
//Print out the sql because we can't dump a prepared statement.
$sql = sprintf('SELECT * FROM mcdb2.addresses
WHERE
addresses_street1 = "%s"
AND addresses_street2 = "%s"
AND addresses_city = "%s"
AND addresses_state = "%s"
AND addresses_zip = "%s"',$this->addresses_street1,$this->addresses_street2,$this->addresses_city,$this->addresses_state,$this->addresses_zip);
$this->logger->log($sql);
if($s->execute())
{
$this->logger->log("Query successful");
$result = $s->get_result();
$this->logger->log(print_r($result,true));
if($result->num_rows == 0)
{
$this->logger->log("This address does not exist. Inserting it now.");
return $this->insert_me();
} else {
$this->logger->log("This address already exists in the database. Loading it instead.");
$row = $result->fetch_assoc();
$this->addresses_id = $row['addresses_id'];
$this->load_me();
return $this->addresses_id;
}
}
}