Question on using Prepared Statements with PHP's PDO
Posted on 2014-01-08
Here is the problem code:
$categoryID = 1;
$productCode = 's%';
$db = new PDO('mysql:host=localhost;dbname=my_database',
$stmt = $db->prepare("SELECT * FROM products WHERE categoryID = :categoryID, AND productCode like :productCode");
$stmt->bindParam(':categoryID', $categoryID, PDO::PARAM_INT);
$stmt->bindParam(':productCode', $productCode, PDO::PARAM_STR);
$products = $db->execute();
When I run the above code, I keep getting an error saying "Fatal error: Call to undefined method PDO::execute()". Yet, when I google sample code for using prepared statements with PDO, they all use the execute() method.
Can someone tell me what's wrong, please? Thanks.