SQL语法错误&合并字符串错误

时间:2016-03-11 21:07:19

标签: php mysql json

下面是一段代码(注意不是完整的代码),它接收一个json对象将一些信息解析为一个数组,并将json对象中的数组转换为字符串,方法是通过implode将数组更改为string并将其添加到pervious中串。

似乎发生了两个问题:

1)它说     第36行/posi_rest_service.php中的数组到字符串转换

 $brontoJSONObject = $_POST['json'];
 $lineItems = ""; 
                $jsonIterator = new RecursiveIteratorIterator(
                new RecursiveArrayIterator(json_decode($brontoJSONObject, TRUE)),
                RecursiveIteratorIterator::SELF_FIRST);
                foreach ($jsonIterator as $key => $val) {
                    if(is_array($val)) {
                            $lineItems .=  '(*)' . (implode("|", $val)); //this is 36!!!!!!!
                        } else {
                            array_push($dataArray, $val);
                            $aCount++;
                        }
                    }
                $result = $conn->prepare("SELECT COUNT(*) FROM bronto_carts WHERE emailAddress = :emailAddress"); 
                $result->bindParam(':emailAddress', $dataArray[8]);
                $result->execute(); 
                $number_of_rows = $result->fetchColumn(); 
                if($number_of_rows > 0) {
                    $tmps = $conn->prepare("DELETE FROM bronto_carts where emailAddress = :emailAddress");
                    $tmps->bindParam(':emailAddress', $dataArray[8]);
                    $tmps->execute();
                }

编辑新错误: 注意:第36行/posi_rest_service.php中的数组到字符串转换

严格标准:只应在第54行的/posi_rest_service.php中通过引用传递变量

1 个答案:

答案 0 :(得分:0)

尝试使用@忽略它。您也可以尝试print_r($ val,true)而不是implode。

$brontoJSONObject = $_POST['json'];
$lineItems = ""; 
            $jsonIterator = new RecursiveIteratorIterator(
            new RecursiveArrayIterator(json_decode($brontoJSONObject, TRUE)),
            RecursiveIteratorIterator::SELF_FIRST);
            foreach ($jsonIterator as $key => $val) {
                if(is_array($val)) {
                        $lineItems .=  '(*)' . (@implode("|", $val)); //this is 36!!!!!!!
                    } else {
                        array_push($dataArray, $val);
                        $aCount++;
                    }
                }
            $result = $conn->prepare("SELECT COUNT(*) FROM bronto_carts WHERE emailAddress = :emailAddress"); 
            $result->bindParam(':emailAddress', $dataArray[8]);
            $result->execute(); 
            $number_of_rows = $result->fetchColumn(); 
            if($number_of_rows > 0) {
                $tmps = $conn->prepare("DELETE FROM bronto_carts where emailAddress = :emailAddress");
                $tmps->bindParam(':emailAddress', $dataArray[8]);
                $tmps->execute();
            }