NYCPHP Meetup

NYPHP.org

[nycphp-talk] Fatal error when trying to connect to dbusingDB/MySQL

Analysis & Solutions danielc at analysisandsolutions.com
Tue Sep 16 12:37:54 EDT 2003


Hi Peter:

> I got it to work by including PEAR.php.

I had a feeling you were calling the DB class incorrectly (and you still
are).  I didn't say anything about it in my last message because I didn't
have an example at my finger tips to show you.  Now I do...

All you need to to is include DB.php, set the DSN and then connect.  The 
database type used is determined by the DSN.

    require_once('DB.php');
    $DSN = 'DB_Type://DB_User:DB_Pass@DB_Protocol+DB_Host:DB_Port/DB_Db';
    $Options['debug'] = 2;

    $db = DB::connect($DSN, $Options);
    if ( DB::isError($db) ) {
        $killProcess('Having problems connecting to the database: '
                . $db->getMessage() );
    }

Enjoy,

--Dan

-- 
     FREE scripts that make web and database programming easier
           http://www.analysisandsolutions.com/software/
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409



More information about the talk mailing list