如何修复错误号:1054 'where clause' 中的未知列 'Array'
How to fix Error Number: 1054 Unknown column 'Array' in 'where clause'
这是我的错误:
A PHP Error was encountered Severity: Notice Message: Array to string
conversion Filename: templates/sidebar.php Line Number: 24 Backtrace:
File:
A:\Sites\PHP_CI\hasan-login\application\views\templates\sidebar.php
Line: 24 Function: _error_handler
File: A:\Sites\PHP_CI\hasan-login\application\controllers\Admin.php
Line: 14 Function: view
File: A:\Sites\PHP_CI\hasan-login\index.php Line: 315 Function:
require_once A Database Error Occurred
Error Number: 1054 Unknown column 'Array' in 'where clause'
SELECT user_menu
.id
, menu
FROM user_menu
JOIN
user_access_menu
ON user_menu
.id
= user_access_menu
.menu_id
WHERE user_access_menu
.role_id
= Array ORDER BY
user_access_menu
.menu_id
ASC
Filename: A:/Sites/PHP_CI/hasan-login/system/database/DB_driver.php
Line Number: 691
我使用 php codeigniter。但是当我删除程序顺利运行的部分时。也许哪里有错误。如何修复此错误?
这是我的代码:
<?php
//error_reporting(0);
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`
FROM `user_menu` JOIN `user_access_menu`
ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = $role_id
ORDER BY `user_access_menu`.`menu_id` ASC
";
$menu = $this->db->query($queryMenu)->result_array();
var_dump($menu);
die;
?>
在 $role_id 变量上使用 printr,我怀疑它是一个数组,这就是你得到这个的原因错误。
这是 codeigniter,你可以使用 codeigniter query builder page 中给出的 OOB 函数,顺便说一下你应该试试这个:
<?php
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`
FROM `user_menu` JOIN `user_access_menu`
ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = ?
ORDER BY `user_access_menu`.`menu_id` ASC
";
$menu = $this->db->query($queryMenu,array($role_id))->result_array();
var_dump($menu);
die;
?>
这是我的错误:
A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: templates/sidebar.php Line Number: 24 Backtrace:
File: A:\Sites\PHP_CI\hasan-login\application\views\templates\sidebar.php Line: 24 Function: _error_handler
File: A:\Sites\PHP_CI\hasan-login\application\controllers\Admin.php Line: 14 Function: view
File: A:\Sites\PHP_CI\hasan-login\index.php Line: 315 Function: require_once A Database Error Occurred
Error Number: 1054 Unknown column 'Array' in 'where clause'
SELECT
user_menu
.id
,menu
FROMuser_menu
JOINuser_access_menu
ONuser_menu
.id
=user_access_menu
.menu_id
WHEREuser_access_menu
.role_id
= Array ORDER BYuser_access_menu
.menu_id
ASCFilename: A:/Sites/PHP_CI/hasan-login/system/database/DB_driver.php Line Number: 691
我使用 php codeigniter。但是当我删除程序顺利运行的部分时。也许哪里有错误。如何修复此错误?
这是我的代码:
<?php
//error_reporting(0);
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`
FROM `user_menu` JOIN `user_access_menu`
ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = $role_id
ORDER BY `user_access_menu`.`menu_id` ASC
";
$menu = $this->db->query($queryMenu)->result_array();
var_dump($menu);
die;
?>
在 $role_id 变量上使用 printr,我怀疑它是一个数组,这就是你得到这个的原因错误。
这是 codeigniter,你可以使用 codeigniter query builder page 中给出的 OOB 函数,顺便说一下你应该试试这个:
<?php
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`
FROM `user_menu` JOIN `user_access_menu`
ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = ?
ORDER BY `user_access_menu`.`menu_id` ASC
";
$menu = $this->db->query($queryMenu,array($role_id))->result_array();
var_dump($menu);
die;
?>