php - PDO not returning any rows -


this setting isn't returning database. it's first time using pdo, i'm missing something. it's not throwing errors @ all, empty result.

$results = array();  $stmt = $bd->prepare("select beer.beer_name, prices.price, prices.shop_name beer, prices beer.beer_name = prices.beer_name , shop_id = :retailer");      $stmt->bindvalue(':retailer', $retailer);   $stmt->execute();    $results[0] = $stmt->fetch(pdo::fetch_assoc); print_r($results[0]); 

you don't need set array before hand, , can check results before using $query->rowcount(). here example using error catching:

try {     // enabled throwing errors - can remove after debugging     $db->setattribute(pdo::attr_errmode, pdo::errmode_exception);     // prepare statement     $stmt = $bd->prepare("select beer.beer_name, prices.price, prices.shop_name beer, prices beer.beer_name = prices.beer_name , shop_id = :retailer");      // can use bindparams, use execute , pass , array shorter     $stmt->execute(array(         ':retailer' => $retailer     ));     if($stmt->rowcount()==0) {         // stuff when no results found (without error)     } else {         $results = $stmt->fetchall();     }  // catch exceptions , put error $e } catch (exception $e) {     // echo error got - should output errors when debugging     echo $e->getmessage(); } 

let me know if have questions, method should give database errors. if don't errors, query isn't returning anything.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -