dpgvdfg321041670 2015-11-04 10:24
浏览 319
已采纳

mysqli_query():行中的空查询

I'm confused by xcode and php due to the fact that the exact same code, which works within the iOS simulator, doesn't work for the iPhone itself.

The php file looks like the following:

<?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);

?>      

When running the code in the iOS simulator it's all fine, but when I run it on my device it says: as the response string in Xcode: "mysqli_query(): Empty query in on line 30". When I work around that error, I don't get the result I expect either.

Every help is greatly appreciated!

  • 写回答

1条回答 默认 最新

  • doqs8936 2015-11-04 10:37
    关注

    Note, that you use BLACKOUT and BLACKEDOUT mixed, and you never use $con. Also, be aware that you define $query inside a loop, so when it iterates zero times, $query never gets defined, thus cannot by used in mysqli_query.

    Try this and come back with the result:

    <?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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口