Question : Cannot connect to DB with PHP PEAR

Hi, connecting directly works, connecting with Pear does not

        print "con:" . mysql_connect("localhost","xxx","yyy");
        print "db:" . mysql_select_db("mydb");

        $dbObj = new DB;
        $this->db = $dbObj->connect($dsn);        
        print "Connection result: " . $this->db . "<br>";

Result:

con:Resource id #57db:1

Connect to dsn mysql://xxx:yyy@localhost/mydb
Connection result: DB Error: not found
could not connect to database

Answer : Cannot connect to DB with PHP PEAR

There must be things you're not showing for your code to work anywhere.  First is the class definition for 'DB' which is not part of PDO that I could find.  Second is the '$dsn' string.  They may be part of an include file somewhere on another project.

The code below is what I got from Pear/PDO.  The complete example above with the info for my database works exactly the same as the direct method that I used before which is like you showed above using 'mysql_connect'.
1:
2:
$dbdsn = "mysql:dbname=$dbname;host=$dbhost";
$dbh = new PDO($dbdsn, $dbuser, $dbpass);
Random Solutions  
 
programming4us programming4us