Avatar of elepil
elepil
 asked on

Question on using Prepared Statements with PHP's PDO

Here is the problem code:

                $categoryID = 1;
                $productCode = 's%';
               
                $db = new PDO('mysql:host=localhost;dbname=my_database',
                                  'username', 'password');
                   
                    $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.
PHPMySQL Server

Avatar of undefined
Last Comment
elepil

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rob

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
elepil

ASKER
Thanks!
Your help has saved me hundreds of hours of internet surfing.
fblack61