简体   繁体   English

PHP PDO提取返回false

[英]PHP PDO fetch returns false

I keep thinking on that "error" but can't say why it returns false. 我一直在思考那个“错误”,但是不能说为什么它返回false。 I've already done a SELECT for this but that is in an other file.. 我已经为此执行了一个SELECT,但这在另一个文件中。

 $result = $db->dbh->prepare("SELECT thumbs FROM skill WHERE id=? LIMIT 1");
 $result->bindParam(1, $id);
    // $id == 4 here
 $result->execute();
 $row = $result->fetch(PDO::FETCH_ASSOC);
    // $row == false > why ?
 $thumbs = $row['thumbs'];

When i'm trying to run this on PhpMyAdmin, it works well. 当我尝试在PhpMyAdmin上运行它时,它运行良好。

I execute this code on an AJAX call, and using the same config.php file for the $db conection. 我在AJAX调用上执行此代码,并对$ db连接使用相同的config.php文件。

Another question: 另一个问题:

    $sql_in = $db->dbh->prepare("INSERT INTO `voted_ip` (id, ip) VALUES (:id, :ip)");
    // $id == 4
    $sql_in->bindParam(":id", $id);
    $sql_in->bindParam(":ip", $ip, PDO::PARAM_STR);
    $sql_in->execute();

it inserts "0" and my ip. 它插入“ 0”和我的IP。 Why 0 ? 为什么是0?

Please help 请帮忙

因为$ id是一个字符串,MySQL将该字符串转换为0。

$id = intval($id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM