沃梦达 / 编程问答 / php问题 / 正文

查询在 phpmyadmin 中有效,但在 PHP 脚本中无效

Query works in phpmyadmin but not in PHP script(查询在 phpmyadmin 中有效,但在 PHP 脚本中无效)

本文介绍了查询在 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 脚本中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:查询在 phpmyadmin 中有效,但在 PHP 脚本中无效

基础教程推荐