Query works in phpmyadmin but not in PHP script(查询在 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 脚本中无效


- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01