gpt4 book ai didi

php - PDO 查询正常,但未提供最终结果

转载 作者:行者123 更新时间:2023-11-29 22:08:54 25 4
gpt4 key购买 nike

我在从远程数据库检索数据时遇到问题。使用 PDO 访问数据库是可以的,我调试。打印行计数,它返回几次出现,但代码似乎在获取时停止

        $arr = $reponse->fetchAll(PDO::FETCH_ASSOC);        

这里是你自己看的链接:http://bacly.fr/baclymphp/getTournois.php

我用另一个数据库做了同样的事情,具有相同的类似代码的功能,它给了我结果

http://bacly.fr/todophp/www/php/getTodo.php

这是我的 getTournois.php 代码:

<?php
require("config.php");

$query="Select t1.tournois_id as tournois_id,t1.tournois_title as tournois_title, t1.tournois_date_debut as tournois_date_debut, t1.tournois_date_fin as tournois_date_fin, t1.tournois_date_limite as tournois_date_limite, coalesce(t2.tournois_inscriptions,0) as tournois_inscriptions, t1.tournois_description as tournois_description, t1.tournois_simple as tournois_simple, t1.tournois_double as tournois_double, t1.tournois_mixte as tournois_mixte ";
$query.= " From ";
$query.= " (select t.tournois_id AS tournois_id, t.tournois_title AS tournois_title, t.tournois_date_debut AS tournois_date_debut, t.tournois_date_fin AS tournois_date_fin, t.tournois_date_limite AS tournois_date_limite, t.tournois_description as tournois_description, t.tournois_simple as tournois_simple, t.tournois_double as tournois_double, t.tournois_mixte as tournois_mixte FROM jnew_tournois_tournois t";
$query.=" order by tournois_date_limite DESC) t1";
$query.= " left join";
$query.= " (select count(ti.tournois_inscriptions_id) as tournois_inscriptions,ti.tournois_inscriptions_tid as tournois_id from jnew_tournois_tournois_inscriptions ti) t2";
$query.= " ON t1.tournois_id = t2.tournois_id order by t1.tournois_date_limite desc";

debug.print($query);

try
{
$bdd = new PDO($db_config['SGBD'] .':host='. $db_config['HOST'] .';dbname='. $db_config['DB_NAME'], $db_config['USER'], $db_config['PASSWORD'], $db_config['OPTIONS']);
$reponse = $bdd->prepare($query);
$reponse->execute();
debug.print("rowcount");
debug.print($reponse->rowcount());

if ($reponse->rowcount() >0){
debug.print('fetching');
$arr = $reponse->fetchAll(PDO::FETCH_ASSOC);
debug.print($arr);

}

}
catch(Exception $e)
{
// En cas d'erreur, on affiche un message et on arrête tout
$result.=$query . "<br>" . $e->getMessage();
debut.print($result);
}
$bdd=null;

echo $result = json_encode($arr);

?>

最佳答案

我认为您的代码按预期工作。我认为误导您认为事实并非如此的部分是 $reponse->rowcount()

来自 PHP 文档,

PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

所以我认为您应该切换到不同的行计数方法,看看这是否会改变计数。看看这些问题

How to get the number of rows grouped by column?

Row count with PDO

关于php - PDO 查询正常,但未提供最终结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31887167/

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