I’ve just tried to start using PDO to handle database access in PHP.
I tried the following code:
$dbh = new PDO("mysql:host=$kdbhost;dbname=$kdbname",$kdbuser,$kdbpw);
$sth = $dbh->("INSERT INTO enquiries (name, email, message) VALUES(:name, :email, :message);");
And dreamweaver gives me a syntax error on the second line, and I can’t figure out for the life of me why?
Note I followed this nettuts tutorial which gave an example without the method name.
You need to do this:
$dbh->(is a syntax error because you’re not calling a method of the$dbhobject. In this case, you want to useprepare()to prepare the query, so you end up with: