Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connection problem PEAR DB.

Status
Not open for further replies.

amanyasin

Technical User
Feb 7, 2003
28
Dear all,
i want to connect Mysql through PEAR DB. i installed PHP5.2.2 with all extensions.when i run fallowing php code,

<?php
// connect
require_once('DB.php');
$db = DB::connect("mysql://root:123@localhost/test");
if (DB::iserror($db)) {
die($db->getMessage( ));
}
// issue the query
$sql = "SELECT * from items";
$q = $db->query($sql);
if (DB::iserror($q)) {
die($q->getMessage( ));
}
// generate the table
while ($q->fetchInto($row)) {
?>
<tr><td><?= $row[0] ?></td>
<td><?= $row[1] ?></td>
<td><?= $row[2] ?></td>
</tr>
<?php
}
?>

It shows an error that " DB.PHP FILE NOT FOUND AT PATH ....... ".
i copied DB.PHP file in PEAR folder then it shows fallowing error msg's.

1- Debug Strict (PHP 5): C:\Program Files\PHP\PEAR\DB.php line 470 - Assigning the return value of new by reference is deprecated.
2- Debug Error: C:\Program Files\PHP\PEAR\DB.php line 946 - Class 'PEAR_Error' not found

And it print the whole DB.PHP file in browser like TXT file.
please guide me, thanks
 
there are a bunch of different issues here.

first, make sure that the pear directory is in the path. including this in your script (at the top) is the easiest way to achieve this if you cannot alter your php.ini file (some hosts prevent this)

Code:
$path = "/absolute/path/to/pear/directory/";
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

it is a bad idea to copy DB.php out of its original location as it relies on relative paths to achieve its functionality. this is the cause of the error 2

"error" 1 is caused by the use of E_STRICT as your error reporting mechanism. I don't know whether PEAR::DB will be updated to comply with PHP5++ as the package is now deprecated in favour of PEAR::MDB2. it does appear, however, still to be maintained.

lastly i would recommend restructuring your error handling as this:

Code:
// connect
require_once('DB.php');
$db = DB::connect("mysql://root:123@localhost/test");
if (PEAR::iserror($db)) {
die($db->getdebuginfo( ));
}



 
Thanks dear for quiding me,
please tell me where i should place "DB.php" file. i am doing all with PHP 5 on my desktop pc.
 
ideally you should install pear through the command line. it's a long time since i have done this on windows (assumption), and I may be rusty.:

open up a command prompt
navigate to the php directory
type
Code:
go-pear
[/code[
respond to the parameter options

when finished type
[code]
pear channel-update pear.php.net
then type
Code:
pear install --alldeps DB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top