In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] writes
>Ok, IM a bit confused as to how PEAR is installed. I read through the README 
>file in the php source but found no explanation. 
>
>I am tryin to use the PEARs DB abstracion. I have DB.php and DB/ in 
>/usr/local/lib/php. I added: 'include_once(DB/mysql.php);' to the top of my 
>script but it failed since it is not finding it. Do I need to assign a path in 
>the php.ini file or have I missed an installation step? 
>
>Can somebody please explain or point me to some docs on how I get up and going 
>with PEAR.

Hi,

Try something like:

<?php
require_once ('DB.php');


// connection
$db_type = "mysql";       // type of database - must correspond to a PEAR type
$db_user = "user";        // database access username
$db_pswd = "password";    // database access password
$db_host = "localhost";   // hostname of database
$db_name = "you_db_name"; // database name

$db_connectString = "$db_type://$db_user:$db_pswd@$db_host/$db_name"; // the above,
collected here for convenience

$usePersistentConnects = true; // true - uses persistent connects to the database
(always leaves a link open, false - not)

if (! $db_con)
        $db_con = DB::connect ($db_connectString, $usePersistentConnects);

$sql = "SELECT column FROM $tableName WHERE whatever = '$whatever'";
                
if (DB::isError ($result = $db_con -> query ($sql)))
        handle_db_error ($result);
else
        $resultArray = $result -> fetchRow (DB_FETCHMODE_ASSOC);

$db_con -> commit();

if ($db_con && (! $usePersistentConnects))
        $db_con -> disconnect();

?>
I hope the line wraps still leave the above readable.

I made a separate function of my own, handle_db_error (), to handle errors - you
might like to do something like:

echo DB::errorMessage($result);

... instead.

I recommend putting all the db connection stuff in a file which resides outside of
the document root and including it where you need it.

The following links may prove useful - the user comments in the phpbuilder article
were particularly helpful in pointing me in the right direction.

http://cvs.php.net/viewcvs.cgi/php4/pear/DB/
http://www.phpdoc.de/pear/index2.html
http://www.phpbuilder.com/columns/allan20010115.php3
http://pear.php.net
http://www.php.net/manual/en/pear.php

All the best,
-- 
Paul Rees

Web Application Programmer/Developer

surfEU.com GmbH

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to