Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2004, 05:57 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default pear db::connect

I have successfully installed pear but it is not connecting to my mysql database and it is not giving an error.
The first script doesnt go beyond DB::Connect and doesnt display hello 1.
The second script(pure php) displays both hello1 and results of the query.
what could be the problem

<?php
require_once 'DB.php';
$uname = 'root';
$hostn = 'localhost';
$db_name = 'employees';
$connection ="mysql://$uname:@$hostn/$db_name";
$db =& DB::connect($connection);
echo "hello1";
if (DB::isError($db))
{ echo $db->getDebugInfo();
   }
echo "hello2";
?>

<?php
$uname = "root";
$hostn = "localhost";
$db_name = "employees";
echo "hello1\n";
$db = mysql_connect($hostn,$uname);
mysql_select_db($db_name,$db);
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
?>



 
Old September 15th, 2004, 05:22 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

The source of the DB class shows the following example:
Code:
<?php
 require_once 'DB.php';

 $dsn = 'mysql://user:password@host/database'
 $options = array(
               'debug'       => 2,
               'portability' => DB_PORTABILITY_ALL,
           );

 $dbh =& DB::connect($dsn, $options);
 if (DB::isError($dbh)) {
     die($dbh->getMessage());
 }
?>
So, try the getMessage() method instead of getDebugInfo() and see if an error message comes up.

HTH!


Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail




Similar Threads
Thread Thread Starter Forum Replies Last Post
PEAR DB Connection failure bxh Beginning PHP 0 October 6th, 2005 10:25 PM
Anybody else learning to HATE pear::DB? biot023 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 March 15th, 2005 04:58 AM
PEAR::DB Using Problem ruhin Beginning PHP 5 June 4th, 2004 12:50 AM
can't connect to mysql using pear sam PHP Databases 2 September 18th, 2003 04:23 PM
Using PEAR DB and Classes. TreacherousDog Beginning PHP 1 July 8th, 2003 01:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.