PHP函数使用mysqli innerjoin

时间:2017-10-08 11:18:11

标签: php mysql

我目前正在尝试从用户可以访问的mysql数据库接收应用程序:

我的问题:

我收到以下错误,可能导致此错误?

[Sun Oct 08 13:08:41.194245 2017] [proxy_fcgi:error] [pid 12486] [client xx.xx.xxx.xxx:xxxxx] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function bind_param() on boolean in /var/www/vhosts/xxx.com/development.xxx.com/modules/database.php:386\nStack trace:\n#0 /var/www/vhosts/pr0b.com/development.pr0b.com/authenticated/applications.php(17): database->getApplicationsById(1)\n#1 {main}\n  thrown in /var/www/vhosts/xxx.com/development.xxx.com/modules/database.php on line 386\n'

我的数据库结构:

表格访问:

id - user_id - product - status - expires

表产品:

id - name - description - download - role

我从数据库获取数据的功能:

function getApplicationsById($id)
{
    $mysqli = new mysqli($this->dBhost, $this->dBusername, $this->dBpassword, $this->dBdatabase);

    if(mysqli_connect_error())
    {
        exit();
        return false;
    }

    $userDataSql = "SELECT * FROM products INNER JOIN access products.id = access.product WHERE access.user_id = ?";
    $stmtData = $mysqli->prepare($userDataSql);
    $stmtData->bind_param("s", $id);
    $stmtData->execute();
    $result = $stmtData->get_result();
    $rows = array();

    while($row = $result->fetch_assoc())
    {
        $rows[] = $row;
    }

    $stmtData->close();
    return $rows;
}

1 个答案:

答案 0 :(得分:0)

您的查询中有错误。在join table_name之后,您必须添加ON,然后指定加入列

变化

 $userDataSql = "SELECT * FROM products INNER JOIN access products.id = access.product WHERE access.user_id = ?";

 $userDataSql = "SELECT * FROM products INNER JOIN access ON products.id = access.product WHERE access.user_id = ?";
  

未捕获错误:在

中的布尔值上调用成员函数bind_param()

表示您的查询返回false而不是数据集。