MYSQL查询PHP - 向 IOS 应用程序返回 nil 的查询 [英] MYSQL Query & PHP - Query returning nil to IOS App

查看:51
本文介绍了MYSQL查询PHP - 向 IOS 应用程序返回 nil 的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的 IOS 应用程序调用一个函数,该函数调用 PHP 文件中的函数,然后应该返回检索到的数据,但由于我在查询中添加了一个新部分,所以它返回 nil.

I am calling a function from my IOS app which calls the function in PHP file which then should return the data retrieved, but it is return nil since I added a new part to my query.

我的新查询在我的数据库上的 MYSQL 测试器服务中工作,但奇怪的是在我的应用程序中返回 nil.

My new query is working in the MYSQL tester service on my DB, but strangely is returning nil in my app.

以下是我在 PHP 文件中设置所有内容的方式:

Here is how I have it all set up in my PHP file:

function fetchAssocStatement($stmt)
    {
        if($stmt->num_rows>0)
        {
            $result = array();
            $md = $stmt->result_metadata();
            $params = array();
            while($field = $md->fetch_field()) {
                $params[] = &$result[$field->name];
            }
            call_user_func_array(array($stmt, 'bind_result'), $params);
            if($stmt->fetch())
                return $result;
        }

        return null;
    }

    // Select all posts + user information made by user with relevant $id
    public function selectPosts($id) {

        // declare array to store selected information
        $returnArray = array();

        /*
        // sql JOIN
        $sql = "SELECT Posts.id,
        Posts.uuid,
        Posts.caption,
        Posts.path,
        Posts.date,
        Posts.imageHeight,
        USERS.id,
        USERS.username,
        USERS.fullname,
        USERS.profileImage
        FROM Posts JOIN USERS ON
        Posts.id = $id AND USERS.id = $id ORDER by date DESC
        LIMIT 0, 5";
        */
        $sql = "SELECT Posts.id,
        Posts.uuid,
        Posts.caption,
        Posts.path,
        Posts.date,
        Posts.imageHeight,
        USERS.id,
        USERS.username,
        USERS.fullname,
        USERS.profileImage,
        coalesce(A.LikeCNT,0)
        FROM Posts INNER JOIN USERS ON 
        Posts.id = $id AND USERS.id = $id
        LEFT JOIN (SELECT COUNT(A.uuidPost) LikeCNT, A.UUIDPost
        FROM Activity A
        WHERE type = "" 
        GROUP BY A.UUIDPOST) A
        on A.UUIDPost = Posts.uuid
        ORDER BY date DESC
        LIMIT 0, 5";


      if($stmt = $this->connection->prepare($sql))
{
    $stmt->execute();
    $stmt->store_result();

    while($row = $this->fetchAssocStatement($stmt))
    {
        $returnArray[] = $row;
    }

    //$stmt->close();
}

        return $returnArray;


    }

正如你所看到的,我有一个注释掉的查询,这是我之前获取帖子的查询(效果很好).但是现在我试图获得所有图像的喜欢计数",在我的应用程序中它什么都不返回......

As you'll be able to see I have a commented out query, which was my previous query for getting the posts(which worked great). But now that I am trying to get the "like count" for all the images, in my app it is return nothing...

如果有人能看到,请告诉我!

If anyone can see one, please let me know!

提前致谢!!

推荐答案

您需要捕获错误.我认为正在执行的 SQL 正在抛出一个错误,而您没有捕获它;这就是为什么没有返回记录的原因.type = "" 在我看来似乎是一个错误.要么你想要 type is null 要么 type = '' (空集)但不是 type = "" 或者你想要 type= 'somevalue' 或根本没有类型值.(完全消除 where 子句)我会从那里开始(消除 where 子句),如果你得到结果,那么你就知道问题出在 where 子句上

You need to trap for errors. I think the SQL being executed is throwing an error and you're not trapping it; which is why no records are being returned. The type = "" seems to be an error in my mind. Either you want type is null or type = '' (empty set) but not type = "" or maybe you want type = 'somevalue' or no value for type at all. (eliminate the where clause entirely) I'd start there (eliminate where clause) and if you get results then you know the problem is with the where clause

这篇关于MYSQL查询PHP - 向 IOS 应用程序返回 nil 的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆