I have the follow 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
Which works, returning one row from $this->statement->rowCount()
.
But, trying to bind params does not work as expected:
// 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
Thanks!
UPDATE:
Changed PDO::FETCH_ASSOC
to PDO::PARAM_STR
because CTRL + C/CTRL + V issues, and #__
to reflect correct database prefix.
Tested with the follow code:
$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());
And all works correctly. I can't find the problem with the other way..