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 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?