php - mysqli_query() : Empty query in line

标签 php ios mysql xcode mysqli

我对 xcode 和 php 感到困惑,因为在 iOS 模拟器中运行的完全相同的代码不适用于 iPhone 本身。

php 文件如下所示:

<?php
$con=mysqli_connect("localhost","BLACKEDOUT","BLACKEDOUT","BLACKEDOUT"     );

$array = json_decode($_POST["identifier"]);

for($i=0; $i < count($array); $i++)
{
$name = $array[$i][1];
for($j=0; $j < count($array[$i][0]); $j++)
{
    $nummer = $array[$i][0][$j];

    $query = "SELECT x FROM Z WHERE uniqueID = $nummer";
    $dbConn = new PDO('mysql:host=localhost;dbname=BLACKEDOUT', "BLACKOUT", "BLACKEDOUT");
    $smt = $dbConn->prepare($query);
    $smt->bindParam(1, $phone_num );
    $smt->execute();
    if($smt->rowCount())
        {
             $ergebnisArray[] = [$name,$nummer];
    }
    else 
    {
    }
     }

}
echo json_encode($ergebnisArray);

mysqli_query($con, $query) or die ("Could not connect to server");

mysqli_close($con);

?>      

在 iOS 模拟器中运行代码时一切正常,但是当我在我的设备上运行它时它说:作为 Xcode 中的响应字符串:“mysqli_query():第 30 行中的空查询”。当我解决该错误时,我也没有得到我期望的结果。

非常感谢您的帮助!

最佳答案

请注意,您混合使用 BLACKOUT 和 BLACKEDOUT,并且您从不使用 $con。另外,请注意您在循环内定义了 $query,因此当它迭代零次时,$query 永远不会被定义,因此不能在 mysqli_query 中使用。

试试这个并返回结果:

<?php
$array = json_decode($_POST["identifier"]);

for($i=0; $i < count($array); $i++)
{
$name = $array[$i][1];
    for($j=0; $j < count($array[$i][0]); $j++)
    {
        $nummer = $array[$i][0][$j];

        $query = "SELECT x FROM Z WHERE uniqueID = '".$nummer."'";
        $dbConn = new PDO('mysql:host=localhost;dbname=BLACKEDOUT', "BLACKOUT", "BLACKEDOUT");
        $smt = $dbConn->prepare($query);
        $smt->bindParam(1, $phone_num );
        $smt->execute();
        if($smt->rowCount())
            {
                 $ergebnisArray[] = [$name,$nummer];
        }
        else 
        {
        }
    }

}
echo json_encode($ergebnisArray);
?>

关于php - mysqli_query() : Empty query in line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33519339/

相关文章:

php - 使用 PHP-MySQL 创建图表

iphone - presentModalViewController - ViewController 在呈现后自动消失

mysql - SQL在数据库结构中允许独立表吗?

PHP:如果花费的时间超过一秒,则跳过 MySql 查询

PHP,计算自添加以来的时间

php - Laravel - 一个节目可以有多个提供者

android - 使用电子邮件在 react-native 中收集表单数据

ios - 在文本矩阵中使用多个 CGAffineTransform

asp.net - 连接到 MySQL 导致错误 "Data source name not found and no default driver specified"

php - 如何让 Apache 服务 index.php 而不是 index.html?