Top Banner
virtual techdays INDIA 18-20 august 2010 Connect to SQL from PHP Praveen SrivatsaDirector, AsthraSoft Consulting Microsoft Regional Director, Bangalore MVP, ASP.NET
19

virtual techdays

Jan 02, 2016

Download

Documents

charde-kaufman

INDIA │ 18-20 august 2010. virtual techdays. Connect to SQL from PHP. Praveen Srivatsa │ Director, AsthraSoft Consulting Microsoft Regional Director, Bangalore MVP, ASP.NET. What is PDO?. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: virtual techdays

virtual techdaysINDIA │ 18-20 august 2010

Connect to SQL from PHP

Praveen Srivatsa│ Director, AsthraSoft ConsultingMicrosoft Regional Director, BangaloreMVP, ASP.NET

Page 2: virtual techdays

What is PDO? • PDO is a PHP extension to formalise

PHP's database connections by creating a uniform interface. This allows developers to create code which is portable across many databases and platforms.

• PDO is not just another abstraction layer like PEAR DB or ADOdb.

Page 3: virtual techdays

Why use PDO?

• Portability

• Performance

• Power

• Easy

• Runtime Extensible

Page 4: virtual techdays

What databases does it support?

• Sybase • Firebird / Interbase• DB2 / INFORMIX (IBM) • MySQL• OCI (Oracle Call Interface)• ODBC• PostgreSQL • SQLite

Now with SQL Server Driver for PHP Support as

well

Page 5: virtual techdays

DSNs

• In generaldrivername:<driver-specific-stuff>

• mysql:host=name;dbname=dbname• odbc:odbc_dsn• oci:dbname=dbname;charset=charset• sqlite:/path/to/db/file• sqlite::memory:

Page 6: virtual techdays

Connect to the database

Page 7: virtual techdays

Persistent PDO Connection

• Connection stays alive between requests

$dbh = new PDO($dsn, $user, $pass,

array( PDO_ATTR_PERSISTENT => true ));

Page 8: virtual techdays

PDO Query (INSERT)

Page 9: virtual techdays

PDO Query (UPDATE)

Page 10: virtual techdays

PDO Query (SELECT)

Page 11: virtual techdays

Error Handling (1)

Page 12: virtual techdays

Error Handling (2)

Page 13: virtual techdays

Error Handling (3)

Page 14: virtual techdays

Error Handling (4)

Page 15: virtual techdays

Prepared statements

Page 16: virtual techdays

Transactions

Page 17: virtual techdays

Get Last Insert Id

Page 18: virtual techdays

BenchmarkSELECT Benchmark Results, 1000 Requests

Library Concurrency Total Time Requests/Sec. Speedup

ADOdb 1 20.90/sec 47.84 -

PDO 1 0.73/sec 1358.62 +2840%

ADOdb 50 10.78/sec 99.23 -

PDO 50 0.54/sec 1850.90 +1865%

ADOdb 100 10.44/sec 95.78 -

PDO 100 0.53/sec 1869.33 +1952%

Page 19: virtual techdays

virtual techdaysTHANKS│18-20 august 2010

[email protected]│ connect.asthrasoft.com/asthratimes