doulian4762 2017-07-07 13:16
浏览 34
已采纳

从服务器上的数据库获取输出,但不在PHP脚本上获取

I have an very nasty issue....

My usage for this code: I wanna get through AJAX, just 5 records everytime i click on the further-button. I´m not so far yet....

This script just have to get me 5 records from a specific user.

The Problem:

So the sql queries run without any problems on the Database. But when i wanna do it in PHP-script, i get ONLY from the first query the counter() AND the second query gives me an empty array from the PDO-Statement.

CODE:

if (empty($_SESSION['counter']) || ($_SESSION['counter'] < 0)) {

      $sql = 'SELECT count(record.record_id) AS counter FROM record 
              LEFT JOIN recordbook ON record.record_id = recordbook.record 
              WHERE user = ?';

              $sth = $this->dbc->prepare($sql);
              $sth->execute(array($u_id['user_id']));
              $count = $sth->fetch();

              $_SESSION['counter'] = $count['counter'];
              var_dump($_SESSION);
          }
          $_SESSION['counter'] = $_SESSION['counter'] - 5;

          $sql = 'SELECT record.record_id, status, place, record.record AS records, comment, recorddate 
                  FROM record LEFT JOIN recordbook ON record.record_id = recordbook.record 
                  WHERE user = ? ORDER BY record.record_id DESC LIMIT ?,5';
          $sth = $this->dbc->prepare($sql);  
          $sth->execute(array($u_id['user_id'],
                                $_SESSION['counter']));

          $output = $sth->fetchAll();
}

HOPE someone know how to solve this...

table structure

Field | Type | Null | Key | Default | Extra
record_id | int(10) unsigned | NO | PRI NULL | auto_increment
status | varchar(200) | YES | NULL | 
place | varchar(200) | YES | NULL 
record | longtext | YES NULL 
comment | longtext | YES | NULL 
recorddate | timestamp | YES | CURRENT_TIMESTAMP 
attachment_id | int(10) unsigned | YES | MUL | NULL
  • 写回答

1条回答 默认 最新

  • douganggu4392 2017-07-08 10:47
    关注

    ok, done! No error....

    need to bind the variables to the query. Seems so, that only with prepare and execute, is it not clear enough. So add bindParam(for integer) or bindValue(for Strings) to code, than it goes nice and smoothly :)

    Have seen that on PHP.net and with debugDumpParams() on PDOStatement you can see, how your Query is working with the Params you setted.

    Here the manual http://php.net/manual/de/pdostatement.debugdumpparams.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题