gpt4 book ai didi

使用 mysqli innerjoin 的 PHP 函数

转载 作者:行者123 更新时间:2023-11-29 18:20:28 25 4
gpt4 key购买 nike

我目前正在尝试从用户有权访问的 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;
}

最佳答案

您的查询有误。在 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 = ?";

Uncaught Error: Call to a member function bind_param() on boolean in

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

关于使用 mysqli innerjoin 的 PHP 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46630494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com