niche Posted February 13, 2019 Share Posted February 13, 2019 (edited) Thought I could alter a table with a pdo query and binding. Apparently not. Is there a way to use a pdo query to alter a table without binding using some kind of variable? if so, what would a simple example look like? Else, I'll use mysqli. Edited February 13, 2019 by niche Link to comment Share on other sites More sharing options...
Funce Posted February 13, 2019 Share Posted February 13, 2019 (edited) Without a binding? You might be able to use a prepared query like this. <?php $stmt = $dbh->prepare("SELECT * FROM REGISTRY WHERE name = ? AND id = ?"); if ($stmt->execute(array($name, $id))) { //Stuff } ?> If you want to see the other ways (mostly binding) you can check it out on the doc page:http://php.net/manual/en/pdo.prepared-statements.php Although I'm perplexed as to why it is imperative to not use a binding. Edited February 13, 2019 by Funce Link to comment Share on other sites More sharing options...
Ingolme Posted February 13, 2019 Share Posted February 13, 2019 Certain elements in queries can't have placeholders, like the LIMIT clause. I haven't tested, but it's probable that ALTER can't have placeholders either since MySQL needs to know the table structure when preparing queries because it uses the data types of the fields to determine how to sanitize the data. If you find yourself having to give the user the ability to alter tables then your database structure may be badly designed. If it is important that you alter tables with variables in the query, you can just put the variables into the SQL string itself, making sure to have carefully sanitized them beforehand. Link to comment Share on other sites More sharing options...
niche Posted February 13, 2019 Author Share Posted February 13, 2019 Quote then your database structure may be badly designed Not badly designed (yet). Bad approach! Many thanks to the fox and Funce. Found this link and learned more about PDO investigating PDO rules. https://stackoverflow.com/questions/9250434/pdo-quote-method Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now