HOW TO define connection with PEAR and PDO?

Talk and info about common issues

Moderator: alexandrleonenko

administrator
Site Admin
Site Admin
Posts: 6180
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO define connection with PEAR and PDO?

Postby administrator » Jun 25th, '11, 14:02

From version 3.2.2 DataFrom allows to use PDO extension for database connections.
(in the next versions we're planning to eliminate the use of PEAR extension, so we strongly recommend to move your application to PDO)

NEW SYNTAX:
Here the examples with using PDO:

Code: Select all

define ("DATAFORM_DIR", "");    /* Ex.: "dataform/" */
require_once(DATAFORM_DIR.'dataform.class.php');

##  *** set needed options and create a new class instance
$debug_mode = false;             /* display SQL statements while processing */   
$messaging = true;                 /* display system messages on a screen */
$unique_prefix = "abc_";         /* prevent overlays - must be started with a letter */
$dform = new DataForm($debug_mode, $messaging, $unique_prefix);

##  *** variables for database connection
$DB_HOST='localhost';               /* usually localhost                       */
$DB_NAME='database_name';     /* usually like this: prefix_dbName        */
$DB_USER='database_user';      /* usually like this: prefix_name          */
$DB_PASS='password';               

$dform->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS);             



OLD SYNTAX:

Here the examples with using PEAR:

Code: Select all

define ("DATAFORM_DIR", "");                     /* Ex.: "dataform/" */
define ("PEAR_DIR", "pear/");                    /* Ex.: "dataform/pear/" */
   
require_once(DATAFORM_DIR.'dataform.class.php');
require_once(PEAR_DIR.'PEAR.php');
require_once(PEAR_DIR.'DB.php');

##  *** variables for database connection
$DB_HOST='localhost';               /* usually localhost                       */
$DB_NAME='database_name';     /* usually like this: prefix_dbName        */
$DB_USER='database_user';      /* usually like this: prefix_name          */
$DB_PASS='password';               

$db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
$result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); } 

##  *** set needed options and create a new class instance
$debug_mode = false;             /* display SQL statements while processing */   
$messaging = true;                 /* display system messages on a screen */
$unique_prefix = "abc_";         /* prevent overlays - must be started with a letter */
$dform = new DataForm($debug_mode, $messaging, $unique_prefix);

$dform->DataSource($db_conn);      

Return to “ApPHP DataForm {HOW TO}”