PHP MySQL插入/更新查询返回true但有错误

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP MySQL插入/更新查询返回true但有错误脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下更新:

$conn->query_cust("update CMS_users set last_login_date = Now() where id = " . $_SESSION['USER_INFO']->id);

我确定问题不在query_cust函数中,因为我在其他几种形式中使用相同的函数并且它们运行良好.无论如何,这是定义(有两个var_dump用于debug-info):

function query_cust($s='',$rows=false,$organize=true) {
    VAR_dump($s);
    if (!$q=MysqL_query($s,$this->con)) return false;
    if ($rows!==false) $rows = intval($rows);
    $rez=array(); $count=0;
    $tyPE = $organize ? MysqL_NUM : MysqL_ASSOC;
    var_dump($q);
    while (($rows===false || $count<$rows) && $line=MysqL_fetch_array($q,$type)) {
        if ($organize) {
            foreach ($line as $field_id => $value) {
                $table = MysqL_field_table($q,$field_id);
                if ($table==='') $table=0;
                $field = MysqL_field_name($q,$field_id);
                $rez[$count][$table][$field]=$value;
            }
        } else {
            $rez[$count] = $line;
        }
        ++$count;
    }
    if (!MysqL_free_result($q)) return false;
    return $rez;
}

执行时,我收到一条警告信息:

string(57) "update cms_users set last_LOGin_date = Now() where id = 1" bool(true)
Warning: MysqL_fetch_array(): supplied argument is not a valid MysqL result resource in /home/content/XX/XXXXXXX/htML/core/MysqL.PHP on line 26

令我担心的是它返回bool(true)但是(如果我错了,请纠正我)一个不可忽视的警告!当我手动将更新查询复制到例如PHPmyAdmin时,它可以工作(用户具有表更新/插入权限).

对于任何遇到相同问题的人来说,只需要几个信息:本地代码运行没有任何问题(即使启用了’error_reporting = E_ALL’),但是当在测试环境(Godaddy的托管)上执行时,警告显示出来.

PS:我不是很喜欢PHP(我来自JAVA世界)所以请在发布你的答案和我的愚蠢的子问题时请求怜悯:)谢谢.

解决方法

如果查询未返回结果集,则每个 the documentation,MysqL_query返回true.更改:

if (!$q=MysqL_query($s,$this->con)) return false;

至:

if (!is_resource($q=MysqL_query($s,$this->con))) return $q;

脚本宝典总结

以上是脚本宝典为你收集整理的PHP MySQL插入/更新查询返回true但有错误全部内容,希望文章能够帮你解决PHP MySQL插入/更新查询返回true但有错误所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。