PHP PDO提取返回false [英] PHP PDO fetch returns false

查看:57
本文介绍了PHP PDO提取返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在思考那个错误",但是不能说为什么它返回false. 我已经为此执行了一个SELECT,但这在另一个文件中.

I keep thinking on that "error" but can't say why it returns false. I've already done a SELECT for this but that is in an other file..

 $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'];

当我尝试在PhpMyAdmin上运行该程序时,效果很好.

When i'm trying to run this on PhpMyAdmin, it works well.

我在AJAX调用上执行此代码,并对$ db连接使用相同的config.php文件.

I execute this code on an AJAX call, and using the same config.php file for the $db conection.

另一个问题:

    $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();

它插入"0"和我的IP.为什么是0?

it inserts "0" and my ip. Why 0 ?

请帮助

推荐答案

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

That is becasue of the $id which is a STRING is converted at 0 by MySQL.

$id = intval($id);

这篇关于PHP PDO提取返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆