Software:
News ToolsReg Shops |
The Register » Software » Spread your database connections with PHP PDOLess is morePublished Thursday 24th April 2008 11:02 GMT To retrieve data from the MySQL database, in a PHP script
$stmt = $connection->prepare("SELECT * from CATALOG WHERE CATALOGID=?");
Set the cursor to be scrollable for the result set returned by the SQL query using the $stmt ->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL); Bind a PHP variable for the $catalogId='catalog1'; $stmt->bindParam(1, $catalogId); Run the prepared statement using the $stmt->execute(); Retrieve a row of data from the result set using the Oracle 10gWe shall use the $db = "oci:dbname=ORCL;host=localhost;port=1521"; $connection = new PDO($db, $user, $password); Similar to the MySQL, database run SQL statements to create a database table, add data to the database table and retrieve data from the table. The IBM DB2 9 Trial VersionWe shall use the
$connection = new PDO('odbc:SAMPLE', $user, $password);
The procedure to create a database table, and for adding data to and for retrieving data from the table is the same as MySQL and Oracle. The advantage of the PDO class library is that PHP scripts that may be run with any database by just modifying the connection parameters for the database specific PDO driver in the PDO constructor. SQL Server 2005 Express EditionWe shall use the SQL Server PDO driver to connect with the SQL Server database. Create a PHP script
$connection=new PDO ('mssql:host=localhost,2107;dbname=tempdb', $user, $password);
The procedure to create a database table, add data to the database table, and retrieve data is the same as for the other databases. In this article you learned to connect to different databases with the PHP PDO drivers using the same set of PHP functions. The same PHP scripts may be used by just modifying the connection parameters.® 16 comments posted — Comment period finished No goodPosted: 11:33 24th April 2008 wtf?Posted: 12:05 24th April 2008 The framework does existsPosted: 12:07 24th April 2008 And then? and then? and then?Posted: 12:18 24th April 2008 PDO is good, but it's not a proper abstraction layerPosted: 12:38 24th April 2008
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search