Page 1 of 1

Translating PEAR::DB classes to mysql

Posted: Thu Mar 27, 2003 3:51 am
by jarow
I am unfamiliar with PEAR::DB classes but would like to use this script for a log in system. Can anyone help me out and translate this to a "normal" mysql connection - especially the parts that define the db_obejct.

Many thanks

Jim

<?php

//require the PEAR::DB classes.

require_once 'DB.php';


$db_engine = 'mysql';
$db_user = 'username';
$db_pass = 'password';
$db_host = 'localhost';
$db_name = 'database';

$datasource = $db_engine.'://'.
$db_user.':'.
$db_pass.'@'.
$db_host.'/'.
$db_name;


$db_object = DB::connect($datasource, TRUE);

/* assign database object in $db_object,

if the connection fails $db_object will contain

the error message. */

// If $db_object contains an error:

// error and exit.

if(DB::isError($db_object)) {
die($db_object->getMessage());
}

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);

// we write this later on, ignore for now.

include('check_login.php');

?>

Posted: Sat Mar 29, 2003 4:47 am
by DocSeuss
not sure what you are asking. Is the question on how to use the the DB package or is it explain how the package works so you can do it another way?

if it is how to use the package go to http://www.appelsiini.net/~tuupola/php/ ... abase.html

I like this mirror opposed to the one on the actual pear site it has MORE documentation and examples.

I would also suggest looking at the DB_DataObject as an option if it fits your needs. For a login script it will and much easier to implement.

If your question is the other I would run out of space before I could explain how it all works.