使用"&" MySQL Query中的字符

时间:2015-08-14 03:05:45

标签: php mysql

无论如何使用"&"在查询中?当我尝试此查询时,返回未定义的变量错误。

"SELECT DISTINCT model FROM carval_data WHERE make = 'A&W' ORDER BY CAST(model AS CHAR)"

编辑:刚才发现它不是MySQL的问题,而是PHP。有解决方案吗

第二次编辑:这是返回的内容

<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/var/www/html/carval.php</b> on line <b>33</b><br /><br />

<b>Notice</b>:  Undefined variable: query in <b>/var/www/html/carval.php</b> on line <b>41</b><br /><br />

<b>Warning</b>:  mysqli_query(): Empty query in <b>/var/www/html/carval.php</b> on line <b>41</b><br /><br />

<b>Warning</b>:  mysqli_error() expects exactly 1 parameter, 0 given in <b>/var/www/html/carval.php</b> on line <b>44</b><br />

这里是第32-50行

foreach($body as $key => $jsons) { 
    foreach($jsons as $key => $value) {
        if($key == 'query'){
            $query = $value;
        }
    }
}

mysqli_set_charset($link, 'utf8');
$result = mysqli_query($link, $query);

if($result === FALSE){
    die(mysqli_error()); 
}

if (!$query) {
    echo 'MySQL Error: ' . mysqli_error();
    exit;
}

0 个答案:

没有答案