Wrap PDO execution code?
Posted: Sun Dec 29, 2013 2:18 pm
Hi,
Is it possible to do something like this:
function runPDO($sql){
}
in a function and pass the sql statements in as needed? It isn't working. I wish to run $arrValues and $row in a loop so I can put the values in a table but it doesn't work. This code works fine outside a function.
I connect to the database in a seperate file that is included in the page. I believe it is a scope issue.
Perhaps there is another way to run queries without repeating the PDO code over and over?
Thanks
Is it possible to do something like this:
function runPDO($sql){
Code: Select all
$stmt = $dbh->prepare($sql);
$stmt->execute();
$arrValues = $stmt->fetchAll(PDO::FETCH_ASSOC);
$row = $stmt->fetch();in a function and pass the sql statements in as needed? It isn't working. I wish to run $arrValues and $row in a loop so I can put the values in a table but it doesn't work. This code works fine outside a function.
I connect to the database in a seperate file that is included in the page. I believe it is a scope issue.
Perhaps there is another way to run queries without repeating the PDO code over and over?
Thanks