PHP With the New PDO::Informix
Presented by: Thomas Beebe
Advanced DataTools Corporation
tom@advancedatatools.com
What is PHP
●
PHP stands for “PHP: Hypertext Preprocessor”
●
Started in 1995 by Rasmus Lerdorf as perl scripts
●
Andi Gutm...
PEAR
●
"PHP Extension and Application Repository"
●
Package management for PHP
●
Offers standards for creating packages fo...
PECL
●
“PHP Extension Community Library”
●
Offers a hosting repository of any and all php
extensions, as well as hosting a...
Why PDO
●
Standardized code and connection methods
●
ODBC can be troublesome
●
The ifx_ driver is not overly stable and is...
Demo 1
Installing
●
Two ways to install:
– extensions (php.ini)
– compiled in (/tmp/php-x.x.x/ext/pdo_informix)
Compiling into PHP
●
Download the latest pdo_informix driver
●
Extract it to php_source/ext [it will be
PDO_INFORMIX-1.0.x...
Connection Paramaters●
$dbh->setAttribute($ATTR,$VALUE);
●
PDO::ATTR_CASE:
– PDO::CASE_LOWER
– PDO::CASE_UPPER
– PDO::CASE...
Demo 2
Binding Paramaters
●
Safer, faster, often easier to manage.
●
Insertions use bindParam();
●
Selects use bindColumn
●
Inser...
Named Bind
●
This tends to be easier to maintain for large
inserts/updates.
●
$stmt = $dbh->prepare(“insert into test (nam...
Binding on Selects
●
This is required for reading blobs from the
database
●
$stmt = $db->prepare("select cat_desc from
cat...
Binding Paramaters
●
LOB needs to be specified, the others are optional
but can help maintain proper data types
●
PDO::PAR...
Error Handling
●
PHP 5 introduced try/catch which can be a
lifesaver.
●
try { sql stuff here...
●
} catch (PDOException $e...
Error Handling (cont)
●
$dbh->errorInfo();
– Returns an array of the last statement executed
– 0: Sqlstate Error Code
– 1:...
Questions?
Thomas Beebe
Advanced DataTools Corporation
tom@advancedatatools.com
Upcoming SlideShare
Loading in...5
×

download presentation

532

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
532
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

download presentation

  1. 1. PHP With the New PDO::Informix Presented by: Thomas Beebe Advanced DataTools Corporation tom@advancedatatools.com
  2. 2. What is PHP ● PHP stands for “PHP: Hypertext Preprocessor” ● Started in 1995 by Rasmus Lerdorf as perl scripts ● Andi Gutmans and Zeev Suraski launched PHP3 in 1997 to replace the dated PHP/FI ● 1998 – PHP 4 ● 2004 – PHP 5 ● Provides a very flexible, expendable application development environment, free to use for any purpose. ● Large collection of modules and extensions available (mostly free of charge)
  3. 3. PEAR ● "PHP Extension and Application Repository" ● Package management for PHP ● Offers standards for creating packages for PHP
  4. 4. PECL ● “PHP Extension Community Library” ● Offers a hosting repository of any and all php extensions, as well as hosting and support for development. ● pdo drivers are provided through pecl.
  5. 5. Why PDO ● Standardized code and connection methods ● ODBC can be troublesome ● The ifx_ driver is not overly stable and is buggy ● Open source development methodology ● IBM support pdo_informix driver ● Proper error handling
  6. 6. Demo 1
  7. 7. Installing ● Two ways to install: – extensions (php.ini) – compiled in (/tmp/php-x.x.x/ext/pdo_informix)
  8. 8. Compiling into PHP ● Download the latest pdo_informix driver ● Extract it to php_source/ext [it will be PDO_INFORMIX-1.0.x] ● Rename it to pdo_informix ● cd .. ● ./buildconf –force [this will rebuild configure] ● ./configure –help | grep informix (make sure it is there) ● ./configure –args --with-pdo- informix=$INFORMIXDIR
  9. 9. Connection Paramaters● $dbh->setAttribute($ATTR,$VALUE); ● PDO::ATTR_CASE: – PDO::CASE_LOWER – PDO::CASE_UPPER – PDO::CASE_NATURAL ● PDO::ATTR_ERRMODE: – PDO::ERRMODE_SILENT – PDO::ERRMODE_WARNING – PDO::ERRMODE_EXCEPTION ● PDO::ATTR_STRINGIFY_FETCHES ● PDO::ATTR_ORACLE_NULLS
  10. 10. Demo 2
  11. 11. Binding Paramaters ● Safer, faster, often easier to manage. ● Insertions use bindParam(); ● Selects use bindColumn ● Insertions: – $name = “Joe Smith”; – $stmt=$dbh->prepare(“insert into tab_a (name) values (?)”); – $stmt->bindParam(1, $name); – $stmt->execute(); – $name = “John Jones”; – $stmt->bindParam(1, $name); – $stmt->execute();
  12. 12. Named Bind ● This tends to be easier to maintain for large inserts/updates. ● $stmt = $dbh->prepare(“insert into test (name) values (:name)”); ● $name = “Papa Smurf”; ● $stmt->bindParam(':name', $name); ● $stmt->execute(); ● $name = “Bubba Jones”;
  13. 13. Binding on Selects ● This is required for reading blobs from the database ● $stmt = $db->prepare("select cat_desc from catalog”); ● $stmt->execute(); ● $stmt->bindColumn(1, $lob, PDO::PARAM_STR); ● $stmt->fetch(PDO::FETCH_BOUND);
  14. 14. Binding Paramaters ● LOB needs to be specified, the others are optional but can help maintain proper data types ● PDO::PARAM_LOB – Data Blobs ● PDO::PARAM_STR – Char/Varchar/Text ● PDO::PARAM_BOOL – Bool ● PDO::PARAM_INT - Integer
  15. 15. Error Handling ● PHP 5 introduced try/catch which can be a lifesaver. ● try { sql stuff here... ● } catch (PDOException $e) { ● print "Error!: " . $e->getMessage() . "<br/>"; ● die(); ● }
  16. 16. Error Handling (cont) ● $dbh->errorInfo(); – Returns an array of the last statement executed – 0: Sqlstate Error Code – 1: Driver specific error number – 2: Driver error message ● Exception handling variable commands – $e->getMessage() = Error message – $e->getLine() = Line Number – $e->getFile() = File that caused the error – $e->getCode() = Code the caused the error – $e->getTrace() = Array of the error trace
  17. 17. Questions? Thomas Beebe Advanced DataTools Corporation tom@advancedatatools.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×