jaymuntz Posted March 3, 2008 Share Posted March 3, 2008 Sample code is below. I am unable to pass a PDOStatement object to a function. It appears that the function never gets called. You can see below that my function just throws an Exception, but the Exception never gets thrown if I've attempted to pass in the PDOStatement object. Running this script in the browser, I get a blank screen with no warnings or errors. I'm baffled. I'm trying to copy a design pattern from page 301 of this book: PHP Objects Patterns , and Practices My Code: [pre] <?php error_reporting(E_ALL); $PDO = new PDO( "mysql:host=localhost;dbname=tewth", "root", "" ); $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $selectByParentId = $PDO->prepare("SELECT name, parentId, sortOrder, id FROM tbl_genres WHERE parentId=:parentId"); $vals = array( ":parentId"=>1 ); //EXECUTE ONE OR THE OTHER executeTheQuery1($selectByParentId, $vals); //won't throw the exception //executeTheQuery2(null, $vals); //will throw the exception //THIS WORKS CORRECTLY IF UNCOMMENTED //$selectByParentId->execute( $vals ); //$array = $selectByParentId->fetch( ); //print_r($array); function executeTheQuery1(PDOStatement $stmt, $values) { throw new Exception("1 - If we could get here, we'd execute the query."); } function executeTheQuery2(PDOStatement $stmt=null, $values) { throw new Exception("2 - If we could get here, we'd execute the query."); } ?> [/pre] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.