Jump to content

Questions about PDO module, prepared statement.


JimTrail
 Share

Recommended Posts

Hello W3SchoolsForums;

 

Question 1: Does the PDO module have to be installed on the server for the below query to work?

 

Question 2: Is the $dbh variable used only to assign to the $stmt variable or does it have an additional use?

 

$stmt = $dbh->prepare("INSERT INTO Customers (CustomerName,Address,City)
VALUES (:nam, :add, :cit)");
$stmt->bindParam(':nam', $txtNam);
$stmt->bindParam(':add', $txtAdd);
$stmt->bindParam(':cit', $txtCit);
$stmt->execute();
Source:
Thanks.
Link to comment
Share on other sites

On older versions of PHP you have to enable the PDO extension to use PDO at all. Whether or not the server supports PDO doesn't affect individual queries though.

 

The page you linked to doesn't show it, but the $dbh variable would presumably be the PDO object itself. There are some examples here of creating a new PDO object:

 

http://php.net/manual/en/pdo.construct.php

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...