[英]Unable to execute query using mysql_query()
我無法執行查詢
if (!mysql_query("SELECT `title`,LEFT(`description`,70) as `description`,`url`
FROM `articles`
WHERE `keywords` LIKE '%blog%'"))
{
echo 'Failed';
}
如果我直接將相同的查詢復制並運行到localhost的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一樣工作,它將被解釋為:
請執行我的查詢 否則,如果我的查詢不正確,請死掉並回顯錯誤。
這不能在生產中使用,但只能在開發期間用於不將技術錯誤消息傳遞給用戶,可以為他們提供有關檢測和/或利用漏洞的重要提示。
也許您的MySQL連接設置不正確。 您的mysql_connect($db_host, $db_user, $db_pass)
嗎? 您是否已使用mysql_select_db()
選擇了正確的數據庫?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.