php - 无法使用 mysql_query() 执行查询

标签 php mysql wamp

我无法执行查询

if (!mysql_query("SELECT `title`,LEFT(`description`,70) as `description`,`url`
                  FROM `articles` 
                  WHERE `keywords` LIKE '%blog%'"))
{
    echo 'Failed';
}

如果我将相同的查询直接复制并运行到本地主机的 SQL 菜单中,它会成功运行。

最佳答案

为什么不用这个

$sql = mysql_query("SELECT `title`,LEFT(`description`,70) as `description`,`url`
              FROM `articles` 
              WHERE `keywords` LIKE '%blog%'") or die (mysql_error());
                                                      //^^^^^^^^^^^^^^^---better use this instead of "failed" to debug, if want change it do it like that **or die ('failed');**

它像 if 一样工作,它会被这样解释:

execute my query please enter image description here or if its not true my query please die and echo the error.


This cant be used in production but only during development for not passing technical error messages to the user, can give them important hints on detecting and/or exploiting vulnerabilities

关于php - 无法使用 mysql_query() 执行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21797882/

相关文章:

php - 在 Windows 上运行在 Cygwin 中编译的 C++ 可执行文件

server - WAMP中的Web服务器根目录在哪里?

javascript - PHP AJAX jQuery 发送文件和文本

php - 接口(interface)和外包

php - 从数据库中排序和提取分数

mysql - 多个别名,一列

使用 WAMP 在浏览器中显示为注释的 PHP 代码

php - 移动重定向 - 返回桌面

javascript - 如何使 bootstrap Voting 片段起作用,改变 MySQL 中的值

sql - 在长插入期间对 MyISAM 表的读访问?