Pear-php-database-abstraction-portability.pdf

  • Uploaded by: Kannan Kumar
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Pear-php-database-abstraction-portability.pdf as PDF for free.

More details

  • Words: 1,613
  • Pages: 17
PEAR DB: What's New In 1.6.0 < Table of Contents   (Previous)

Table of Contents

(Next)   Introduction to PEAR DB >

Title PEAR DB: What's New in 1.6.0 New York PHP Monthly Meeting February 24, 2004 by Daniel Convissor The Analysis and Solutions Company

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/[9/12/2009 6:26:05 PM]

© The Analysis and Solutions Company

Introduction to PEAR DB < Title   (Previous)

Table of Contents

(Next)   Improvements in DB 1.6.0 >

Introduction to PEAR DB PEAR: PHP Extension and Application Repository Object oriented API Handles 13 of PHP's database extensions dBase, FrontBase, InterBase, Informix, mSQL, MS SQL Server, MySQL, MySQLi, Oracle, ODBC (tested DB2 & Access), PostgreSQL, SQLite, Sybase

Please Note: Sample code has been significantly simplified If viewing on the web: set browser to full screen / kiosk mode and change font size / zoom until this page fits comfortably in the whole screen Opera 7 Win32 users: our style sheet may cause rendering delays, even though it's valid Footer placement works right in Mozilla on multiple OS's, but IE and Opera only on Windows

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/intro.php[9/12/2009 6:26:08 PM]

© The Analysis and Solutions Company

Improvements in DB 1.6.0 < Introduction to PEAR DB   (Previous)

Table of Contents

(Next)   Improvements in DB 1.6.0 cont'd >

Improvements in DB 1.6.0 Really works for more than just MySQL. New portability features, making it possible to write applications which can be easily ported between DBMS's. Prepare/execute works the same way for all DBMS's and allows escaping of placeholder characters. PHP 5 compatibility. PHP must be at version 4.2.0 or higher.

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/improved1.php[9/12/2009 6:26:09 PM]

© The Analysis and Solutions Company

Improvements in DB 1.6.0 cont'd < Improvements in DB 1.6.0   (Previous)

Table of Contents

(Next)   connect.inc >

Improvements in DB 1.6.0 cont'd Introduced experimental mysqli driver Deployed tableInfo() in more drivers and finalized the move from DB_result to DB_common. Added quoteSmart() and quoteSimple(), deprecating the inconsistent quote() and quoteString(). Improved error reporting. Countless documentation corrections.

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/improved2.php[9/12/2009 6:26:11 PM]

© The Analysis and Solutions Company

connect.inc < Improvements in DB 1.6.0 cont'd   (Previous)

Table of Contents

(Next)   Portability: Lowercasing >

connect.inc toString()); } $oracle =& DB::connect("oci8://$ouser:$opw@/$odb"); if (DB::isError($oracle)) { die($oracle->toString()); } $pgsql =& DB::connect("pgsql://$puser:$ppw@/$pdb"); if (DB::isError($pgsql)) { die($pgsql->toString()); } $sqlite =& DB::connect("sqlite:///$sdb?mode=0666"); if (DB::isError($sqlite)) { die($sqlite->toString()); } ?>

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/connect.php[9/12/2009 6:26:13 PM]

© The Analysis and Solutions Company

Portability: Lowercasing < connect.inc   (Previous)

Table of Contents

(Next)   Portability: Right Trim >

Portability: Lowercasing require_once './examples/connect.inc'; $$dbms->query('CREATE TABLE tbl (Cf CHAR(10))'); $$dbms->query("INSERT INTO tbl VALUES ('DOH!')"); $$dbms->setFetchMode(DB_FETCHMODE_ASSOC); $row =& $$dbms->getRow('SELECT Cf FROM tbl'); if (isset($row['cf'])) { echo 'mmm... sweet candy...'; } else { print_r($row); } $$dbms->query('DROP TABLE tbl');

Default Behavior $dbms = 'mysql';

Array ( [Cf] => DOH! )

$dbms = 'pgsql';

mmm... sweet candy...

$$dbms->setOption('portability', DB_PORTABILITY_LOWERCASE); $dbms = 'mysql';

mmm... sweet candy...

PEAR DB: What's New In 1.6.0

$dbms = 'pgsql';

mmm... sweet candy...

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/lower.php[9/12/2009 6:26:15 PM]

© The Analysis and Solutions Company

Portability: Right Trim < Portability: Lowercasing   (Previous)

Table of Contents

(Next)   Portability: Null to Empty >

Portability: Right Trim require_once './examples/connect.inc'; $$dbms->query('CREATE TABLE tbl (c CHAR(10))'); $$dbms->query("INSERT INTO tbl VALUES ('one')"); $c =& $$dbms->getOne('SELECT c FROM tbl'); if ($c == 'one') { echo 'Time for a Scooby Snack!'; } else { echo "ZOINKS! \$c='$c' strlen=" . strlen($c); } $$dbms->query('DROP TABLE tbl');

Default Behavior $dbms = 'oracle';

ZOINKS! $c='one

' strlen=10

$dbms = 'mysql';

Time for a Scooby Snack!

$$dbms->setOption('portability', DB_PORTABILITY_RTRIM); $dbms = 'oracle';

Time for a Scooby Snack!

PEAR DB: What's New In 1.6.0

$dbms = 'mysql';

Time for a Scooby Snack!

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/trim.php[9/12/2009 6:26:17 PM]

© The Analysis and Solutions Company

Portability: Null to Empty < Portability: Right Trim   (Previous)

Table of Contents

(Next)   Portability: Error Mapping >

Portability: Null to Empty require_once './examples/connect.inc'; $$dbms->query('CREATE TABLE WMDs (c CHAR(10) NULL)'); $$dbms->query("INSERT INTO WMDs VALUES ('')"); $c =& $$dbms->getOne('SELECT c FROM WMDs'); if (isset($c)) { echo 'Vote! And organize others to vote!'; } else { echo "W's scruples: " . gettype($c); } $$dbms->query('DROP TABLE WMDs');

Default Behavior $dbms = 'oracle';

W's scruples: NULL

$dbms = 'pgsql';

Vote! And organize others to vote!

$$dbms->setOption('portability', DB_PORTABILITY_NULL_TO_EMPTY); $dbms = 'oracle';

Vote! And organize others to vote!

PEAR DB: What's New In 1.6.0

$dbms = 'pgsql';

Vote! And organize others to vote!

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/null.php[9/12/2009 6:26:18 PM]

© The Analysis and Solutions Company

Portability: Error Mapping < Portability: Null to Empty   (Previous)

Table of Contents

(Next)   Portability: Error Mapping Example >

Portability: Error Mapping MySQL unique/primary key violations: already exists -> constraint violation MySQL not-null violations: constraint violation -> null value

violates not-null constraint

MS Access ODBC bogus field: mismatch -> no such field In 1.6.0 this must be set during connect(). 1.6.1 will allow configuration via setOption().

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/errorport.php[9/12/2009 6:26:20 PM]

© The Analysis and Solutions Company

Portability: Error Mapping Example < Portability: Error Mapping   (Previous)

Table of Contents

(Next)   Portability: Delete Count >

Portability: Error Mapping Example require_once './examples/connect.inc'; $$dbms->query('CREATE TABLE tbl (c CHAR(10) NOT NULL)'); $result =& $$dbms->query('INSERT INTO tbl VALUES (NULL)'); if ($result->getMessage() == 'DB Error: null value violates not-null constraint') { echo 'Phew, the pointy-haired guy went away!'; } else { echo 'AAAAGH! ' . $result->getMessage(); } $$dbms->query('DROP TABLE tbl');

Default Behavior $dbms = 'mysql';

$dbms = 'oracle';

AAAAGH! DB Error: constraint violation Phew, the pointy-haired guy went away! $$dbms->setOption('portability', DB_PORTABILITY_ERRORS); $dbms = 'mysql';

Phew, the pointy-haired guy went away!

PEAR DB: What's New In 1.6.0

$dbms = 'oracle';

Phew, the pointy-haired guy went away!

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/errorportex.php[9/12/2009 6:26:22 PM]

© The Analysis and Solutions Company

Portability: Delete Count < Portability: Error Mapping Example   (Previous)

Table of Contents

(Next)   Portability: Usage >

Portability: Delete Count require_once './examples/connect.inc'; $$dbms->query('CREATE TABLE tbl (c CHAR(10))'); $$dbms->query("INSERT INTO tbl VALUES ('one')"); $$dbms->query('DELETE FROM tbl'); $count = $$dbms->affectedRows(); if ($count != 0) { echo 'Yes!'; } else { echo 'Does everything have to be funny?'; } $$dbms->query('DROP TABLE tbl');

Default Behavior $dbms = 'sqlite';

Does everything have to be funny?

$dbms = 'pgsql';

Yes!

$$dbms->setOption('portability', DB_PORTABILITY_DELETE_COUNT); $dbms = 'sqlite';

Yes!

PEAR DB: What's New In 1.6.0

$dbms = 'pgsql';

Yes!

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/delete.php[9/12/2009 6:26:24 PM]

© The Analysis and Solutions Company

Portability: Usage < Portability: Delete Count   (Previous)

Table of Contents

(Next)   Portability: Constants are Bitwised >

Portability: Usage Portability options can be set when connecting... DB_PORTABILITY_ALL, ); $db =& DB::connect('pgsql:///foo', $options); if (DB::isError($db)) { die($db->getMessage()); } ?>

... or during runtime... setOption('portability', DB_PORTABILITY_ALL); ?>

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/usage.php[9/12/2009 6:26:26 PM]

© The Analysis and Solutions Company

Portability: Constants are Bitwised < Portability: Usage   (Previous)

Table of Contents

(Next)   Portability: Backwards Compatibility >

Portability: Constants are Bitwised Portability mode constants are bitwised. Can combine them using | and remove them using ^. Turn on all portability options: $db->setOption('portability', DB_PORTABILITY_ALL);

Enable lowercasing and trimming: $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);

Enable all options except trimming: $db->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/bitwise.php[9/12/2009 6:26:28 PM]

© The Analysis and Solutions Company

Portability: Backwards Compatibility < Portability: Constants are Bitwised   (Previous)

Table of Contents

(Next)   Important tableInfo() Changes >

Portability: Backwards Compatibility Portability used to be handled by the optimize option. optimize

is now deprecated.

Old scripts work under the new system. If optimize gets set to go into these modes:

portability

the following drivers

oci8: DB_PORTABILITY_LOWERCASE and DB_PORTABILITY_DELETE_COUNT fbsql, mysql, mysqli, sqlite: DB_PORTABILITY_NUMROWS

If optimize gets set to performance new portability system is switched off.

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/bc.php[9/12/2009 6:26:29 PM]

© The Analysis and Solutions Company

Important tableInfo() Changes < Portability: Backwards Compatibility   (Previous)

Table of Contents

(Next)   Error Code Fixes >

Important tableInfo() Changes Finalized move to the DB_common class. Added to Sybase and Informix. Examine a table by passing a table name: tableInfo('tablename'); print_r($info); ?>

Probe a query result by passing a DB_result object: query('SELECT * FROM tablename'); $info = $db->tableInfo($result); print_r($info); ?>

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/tableinfo.php[9/12/2009 6:26:31 PM]

© The Analysis and Solutions Company

Error Code Fixes < Important tableInfo() Changes   (Previous)

Table of Contents

(Next)   More Information About PEAR DB >

Error Code Fixes mssql: errorCode() returns DB's code instead of SQL Server's code. Added errorNative() to get Server's code. Added mappings in several drivers to provide consistency between ibase, ifx, mssql, oci8, odbc(db2), pgsql, sqlite and sybase. If error code portability is turned on, that consistency is expanded to mysql, mysqli and odbc(access). Added DB_ERROR_CONSTRAINT_NOT_NULL for handling null values in NOT NULL columns.

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/errors.php[9/12/2009 6:26:33 PM]

© The Analysis and Solutions Company

More Information About PEAR DB < Error Code Fixes   (Previous)

Table of Contents

 

More Information About PEAR DB Home Page: http://pear.php.net/package/DB Manual Change Log Installation Instructions CVS HTTP: http://cvs.php.net/cvs.php/pear/DB CVS: cvs -d:pserver:[email protected]:/repository login # password is: phpfi cvs -d :pserver:[email protected]:/repository co pear/DB

PEAR DB: What's New In 1.6.0

New York PHP 2004 -02 -24

http://www.nyphp.org/content/presentations/db160/moreinfo.php[9/12/2009 6:26:35 PM]

© The Analysis and Solutions Company

More Documents from "Kannan Kumar"

Doc1.docx
November 2019 23
Script_peardb.pdf
November 2019 13
Pbug.pdf
November 2019 12
Node-dev.pdf
November 2019 15