php不能在linux服务器上的mysql查询中使用撇号
我被一个奇怪的问题吓坏了。当我从phpmyadmin执行此查询时,它工作正常,并返回2个结果。但当我们执行这个查询表单php页面时,它返回0结果php不能在linux服务器上的mysql查询中使用撇号,php,mysql,linux,Php,Mysql,Linux,我被一个奇怪的问题吓坏了。当我从phpmyadmin执行此查询时,它工作正常,并返回2个结果。但当我们执行这个查询表单php页面时,它返回0结果 $query = "SELECT distinct(vtiger_products.product_no) FROM `vtiger_products` INNER JOIN vtiger_crmentity VC ON VC.crmid = vtiger_products.productid inner join vtiger_t
$query = "SELECT distinct(vtiger_products.product_no) FROM `vtiger_products`
INNER JOIN vtiger_crmentity VC ON VC.crmid = vtiger_products.productid
inner join vtiger_tree_product vtp on vtiger_products.productid = vtp.productid";
$custom_conditions = ' cf.cf_1399 = "'.$_REQUEST['size'].'"';
$temp ='Where vtiger_products.hisotrization_status='Current'
AND vtiger_products.productid > 0
AND VC.deleted = 0
AND vtp.nodeid in (425,426,427,428,430,431,457,458,459,460,480,488,502,510,514,515,516,517,518,519,520,521,525,526,527,528,529)';
if ($custom_conditions) {
$query .= " inner JOIN vtiger_productcf cf on cf.productid = vtiger_products.productid ";
$conditions .= " AND ( " . str_replace('""','\""',str_replace("''","\''",$custom_conditions)) . " ) ";
}
$query = $query.$temp . $conditions;
SELECT distinct(vtiger_products.product_no) FROM `vtiger_products`
INNER JOIN vtiger_crmentity VC ON VC.crmid = vtiger_products.productid
inner join vtiger_tree_product vtp on vtiger_products.productid = vtp.productid
inner JOIN vtiger_productcf cf on cf.productid = vtiger_products.productid
Where vtiger_products.hisotrization_status='Current'
AND vtiger_products.productid > 0
AND VC.deleted = 0
AND vtp.nodeid in (425,426,427,428,430,431,457,458,459,460,480,488,502,510,514,515,516,517,518,519,520,521,525,526,527,528,529)
AND ( cf.cf_1399 = "20'" );
等待您的响应,谢谢您可以使用函数mysql\u real\u escape\u strings将php变量传递到查询中,以在SQL语句中使用字符串中的特殊字符
e.g.mysql_real_escape_string($user);
简单明了:
错:
$query = '... set test = 'blah' where ...'; (' before blah terminates the string)
解决方案1:
$query = '... set test = \'blah\' where ...'; (escaping)
解决方案2:
$query = "... set test = 'blah' where ..."; (double quotes aren't terminated by single quotes)
请注意,您好,$test!计算$test,同时计算“您好,$test!”没有。您是否使用php中的变量来设置查询中的一个值?如果是这样,请同时发布PHP代码。请发布PHP文件中的整行内容,而不仅仅是SQL字符串。向我们展示您的PHP脚本查看您的帖子,vtiger_products是单间隔的这一事实意味着您使用了反勾号,而不是撇号如果查询在PHP字符串文字中,您需要转义用于分隔字符串的同一引号的任何用法。mysql_*函数已弃用。请输入mysqli_*equillents或PDO。