0
I’m trying to send some values to SQL, but PDO does not work as it should, or I’m forgetting something, I’m new to using PDO.
Example of functional code.
$conn = new PDO('mysql:dbname=config_database;host=127.0.0.1', 'root', '');
$statement = $conn->prepare("UPDATE stream_table SET src='Funcional' WHERE start = '60'");
$statement->execute();
Example of non-functional code.(I tried several other possibilities unsuccessfully) (Returns no error, just does nothing)
$conn = new PDO('mysql:dbname=config_database;host=127.0.0.1', 'root', '');
//$value = $_POST['value']; //A ideia real é pegar via POST
$value = 'C:\sample.code'; //Simplificando o test
$statement = $conn->prepare("UPDATE stream_table SET src='?' WHERE start = '60'");
$statement->bindValue(":value", $value); //Testei com bindParam e bindValue
$statement->execute();
I do not know if it is due to the apostrophe or something else, I followed several examples contained in the internet and it doesn’t even work, it is malignant.
How can I run this command functionally?
Maybe this post here from the OS-pt will help.
@Edit
Error note: I cannot use placeholders for table or column names.
Not related to the question, but I particularly likemysqli_ more than PDO. They are similar, but it seems to me more natural mysqli_. As for the apostrophes, note that they should not be used in placeholders of the parameters (
?
), as exemplified in the @Lost reply.– Bacco
I also findmysqli_ easier and easier to use, but with a little time using PDO, I started to like how it is written and everything. It gives me confidence to use PDO, besides the compatibility with several drivers, I see only advantage, even if it is more complicated. Anyway, I think that each one should use what suits them best and is more comfortable. @Bacco (PS.: I’m sorry for the silly questions, always at the beginning when we are noobs we have these doubts.)
– Florida
in fact, both have their advantages. If it seemed like criticism, it was not the intention, I only commented as personal preference even. As for what he asked, Perdeu put the two important points: the use of the names x numbers, and the quotation marks, which affected his code.
– Bacco