JoshEir Posted March 17, 2021 Share Posted March 17, 2021 (edited) I'd love to use anonymous placeholders on my ecommerce site project. I am writing half with php and half with golang. On the three examples below, when run, gives the following exception, " Error: Call to a member function execute() on string. " I tried it with a decimal too. Thanks in advance. $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindParam(1, $productID, PDO::PARAM_INT); $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindValue(1, $productID, PDO::PARAM_INT); $stmt->execute(); Here is the rest of the code : <?php $filename = ""; $keyword1 = $_GET['keyword']; $titleOfSelectedDropDown = $_GET['val1']; $fileID = ""; $imageID = "a"; $displayID = ""; $keyword1 = "test"; $titleOfSelectedDropDown = "cc"; $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $gKeyword1 = ""; $gKeyword2 = ""; $gKeyword3 = ""; $key1ID = ""; $key2ID = ""; $key3ID = ""; $string1 = "<center><h1><u>Search Results</u><h1></center></p>"; $dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); $test = "1"; $stmt->execute([ $test ]); Edited March 17, 2021 by JoshEir mistake Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/ Share on other sites More sharing options...
Solution Barand Posted March 17, 2021 Solution Share Posted March 17, 2021 (edited) Too many "="s. $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); ^ REMOVE EDIT: Turn on your error reporting. Edited March 17, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585154 Share on other sites More sharing options...
JoshEir Posted March 17, 2021 Author Share Posted March 17, 2021 (edited) Thank you, I would never have suspected that! Hence, this error reporting is important, is it an extension? I'm using Visual Code. Josh Edited March 17, 2021 by JoshEir Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585155 Share on other sites More sharing options...
Barand Posted March 17, 2021 Share Posted March 17, 2021 4 minutes ago, JoshEir said: this error reporting is important, is it an extension? The settings are in you "php.ini" file. I have highlighted the settings you want for development. On a production site you would log errors instead of displaying them. Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585156 Share on other sites More sharing options...
JoshEir Posted March 17, 2021 Author Share Posted March 17, 2021 I am having trouble with my phone to set up pay pal. I'll get to it soon. Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585157 Share on other sites More sharing options...
Barand Posted March 17, 2021 Share Posted March 17, 2021 Hmm! I would have expected your original code to throw a syntax error. Apparently it doesn't. Very odd.. Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585158 Share on other sites More sharing options...
Barand Posted March 17, 2021 Share Posted March 17, 2021 1 minute ago, JoshEir said: I am having trouble with my phone to set up pay pal. I'll get to it soon. Don't lose any sleep over it Quote Link to comment https://forums.phpfreaks.com/topic/312307-exceptions-with-prepare/#findComment-1585159 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.