douchen4915 2016-04-22 16:24
浏览 105
已采纳

尝试获取行数时,PDO上的fetchColumn错误

I'm trying to move to PDO.

I want to do a classic query for checking number of rows, in mysql I would have done mysql_num_rows_result but I've read somewhere that in PDO it does not work.

So I've tried with a fetch column using the following code :

global $bdd;
            $login = $bdd->query("SELECT
                   COUNT
                    FROM spb_clients_acces_compte,
                         spb_clients_infos_generales
                    WHERE spb_clients_acces_compte.spb_clients_acces_compte_e_mail = '{$email}'
                    AND spb_clients_acces_compte.spb_clients_acces_compte_pwd_md5 = '{$pass}'
                    AND spb_clients_acces_compte.spb_clients_acces_compte_admin = 1");
            $reponse = $bdd->fetchColumn();
            if ($reponse == 0):

            elseif ($reponse == 1):

            else:
            endif;
            var_dump($reponse);

This return to me :

( ! ) Fatal error: Call to undefined method PDO::fetchColumn() in C:\wamp\www\spb2016\admin\core\login.php on line 20

Line 20 is : $reponse = $bdd->fetchColumn();

I've tried many things with no success

Anykind of help will be much appreciated.

  • 写回答

1条回答 默认 最新

  • douzhunlan5930 2016-04-22 16:43
    关注

    First of all, you need to add a column to your COUNT function. COUNT is a mysql function that returns the number of whatever parameter you pass it, so COUNT(id) would work.

    Second, you must use the PDOStatement in order to fetch results. Replace

    $reponse = $bdd->fetchColumn();
    

    with

    $reponse = $login->fetchColumn();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化