查询在phpmyadmin中有效,但在PHP脚本中无效 [英] Query works in phpmyadmin but not in PHP script

查看:72
本文介绍了查询在phpmyadmin中有效,但在PHP脚本中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了类似的问题,但还不能解决我的问题.这是相关代码:

I found similar questions but can't solve my problem yet. Here is the relevant code:

$query = "SELECT * FROM conceptos WHERE descripcion = '$descripcion'";
if ($result = mysql_query($query,$connection)){
    if (mysql_num_rows($result) > 0){
        //Do something
    } else {
        die($query);
        exit;
    }
} else {
    die(mysql_errno() . ' - ' . mysql_error());
    exit;
}

我在连接或权限方面没有问题,因为此代码段位于循环内,其他查询进入执行操作"部分.但是,当我接受回显的查询并在phpMyAdmin中执行它时,它会按预期返回1值.为什么?什么原因会导致这种行为?预先感谢您的任何建议.

I don't have problems with the connection or the permissions, because this code snippet is inside a loop and the other queries enter the "Do something" section. But when I take the echoed query and execute it in phpMyAdmin, it returns 1 value as expected. Why? What reasons can lead to this behavior? Thanks in advance for any advice.

推荐答案

我遇到了这个问题,发现这是因为我通过直接从MS Word复制/粘贴到数据库中来阻塞数据库.粘贴插入了特殊的斜撇号,PHPMYADMIN显然可以解析斜撇号,但是我的php代码无法解析.一旦我用标准的单引号替换了它们,一切就好了.

I had this problem and found that it was because I junked up my database by copy/pasting directly to the database from MS Word. Pasting had inserted special slanted apostrophes that PHPMYADMIN could apparently parse but my php code could not. Once I replaced those with a standard single quote, all was well.

这篇关于查询在phpmyadmin中有效,但在PHP脚本中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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