MySQL查询是否可能太长并导致一些问题?
我想从用户那里将browser_version和platform以及user_agent等保存到数据库中。
我使用this PHP类并拥有以下代码:
include_once('database_connect.php');
include_once('clean.php');
include_once('class.browserversion.php');
$browser = new Browser();
$browser_name = clean($browser->getBrowser());
$browser_version = clean($browser->getVersion());
$browser_platform = clean($browser->getPlatform());
$browser_is_mobile = clean($browser->isMobile());
$browser_user_agent = clean($browser->getUserAgent());
if($browser_is_mobile == FALSE):
$browser_is_mobile = 0;
elseif($browser_is_mobile == TRUE):
$browser_is_mobile = 1;
endif;
$qry = "INSERT INTO map_user_browser (user_id, browser_name, browser_version, browser_platform, browser_is_mobile, browser_user_agent) VALUES('".$user_id."', '".$browser_name."', '".$browser_version."', '".$browser_platform.", '".$browser_is_mobile."', '".$browser_user_agent."'";
$result = @mysql_query($qry) or die(mysql_error());
我总是收到You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, l' at line 1
但是当我为每个字段进行多次查询时,一切正常。可能有什么不对?
答案 0 :(得分:1)
试试这个:
$qry = "INSERT INTO map_user_browser (user_id, browser_name, browser_version, ".
"browser_platform, browser_is_mobile, browser_user_agent) VALUES('".$user_id."', ".
"'".$browser_name."', '".$browser_version."', '".$browser_platform."', ".
"'".$browser_is_mobile."', '".$browser_user_agent."')";
在查询结束时,$ browser_platform和“)”之后您错过了'。