gpt4 book ai didi

php - PDO 查询一半时间返回 False

转载 作者:行者123 更新时间:2023-11-29 09:07:38 24 4
gpt4 key购买 nike

我的 PDO mysql 查询有问题

这是我的简单代码(不是真实情况,只是为了向您展示问题)

$connexion = new PDO(SQL_DSN, SQL_USERNAME, SQL_PASSWORD);
$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
$stmt->execute(array(":mission" => '1'));
$ligne = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($stmt);

$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
var_dump($stmt);
$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
var_dump($stmt);

和输出:

object(PDOStatement)[2]
public 'queryString' => string 'SELECT * from missions,platforms WHERE missions_platforms_id = platforms_id AND missions_id = :mission' (length=122)

boolean false

object(PDOStatement)[2]
public 'queryString' => string 'SELECT * from missions,platforms WHERE missions_platforms_id = platforms_id AND missions_id = :mission' (length=122)

为什么第二个 var_dump 返回 false ?

如果我对相同的模式执行多次,它一半的时间会返回 false...

谢谢你

最佳答案

使用 PDOStatement::closeCursor() 使用 PDOStatement::fetch() 读取结果集后尝试关闭结果集游标如:

$connexion = new PDO(SQL_DSN, SQL_USERNAME, SQL_PASSWORD);
$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
$stmt->execute(array(":mission" => '1'));
$ligne = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($stmt);
$stmt->closeCursor();

$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
var_dump($stmt);
$stmt = $connexion->prepare('SELECT * from missions,platforms WHERE missions_platforms_id = exl_platforms_id AND missions_id = :mission');
var_dump($stmt);

第一个语句是您实际从中获取结果的唯一语句。

关于php - PDO 查询一半时间返回 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com