我有以下 PDO:
// Connect to PDO / $this->link = PDO
$this->statement = $this->link->prepare("
SELECT p.*, pm.*
FROM dev_permissions p, dev_permissions_menu pm
WHERE pm.id = p.permission_menu_id
AND pm.module = 'account'
AND pm.controller IN('login', '*')
AND pm.action IN('index', '*')
");
// Execute and verify number of rows
哪个有效,从 . 返回一行$this->statement->rowCount()
。
但是,尝试绑定参数不能按预期工作:
// Connect to PDO / $this->link = PDO
$this->statement = $this->link->prepare("
SELECT p.*, pm.*
FROM dev_permissions p, dev_permissions_menu pm
WHERE pm.id = p.permission_menu_id
AND pm.module = :module
AND pm.controller IN(:controller, '*')
AND pm.action IN(:action, '*')
",
$this->statement->bindParam(':module', 'account', PDO::PARAM_STR);
$this->statement->bindParam(':controller', 'login', PDO::PARAM_STR);
$this->statement->bindParam(':action', 'index', PDO::PARAM_STR);
// Execute and verify number of rows
谢谢!
更新:
更改PDO::FETCH_ASSOC
为PDO::PARAM_STR
因为 CTRL + C/CTRL + V 问题,并#__
反映正确的数据库前缀。
使用以下代码进行测试:
$pdo = new \PDO('mysql:dbname=database;host=localhost', 'user', 'password');
$statement = $pdo->prepare("
SELECT p.*, pm.*
FROM dev_permissions p, dev_permissions_menu pm
WHERE pm.id = p.permission_menu_id
AND pm.module = :module
AND pm.controller IN(:controller, '*')
AND pm.action IN(:action, '*')
");
$statement->bindParam(':module', $request['module'], \PDO::PARAM_STR);
$statement->bindParam(':controller', $request['controller'], \PDO::PARAM_STR);
$statement->bindParam(':action', $request['action'], \PDO::PARAM_STR);
$statement->execute();
new \Core\Debug($statement->fetchAll());
一切正常。我找不到其他方式的问题..