XAMPP + PEAR: MDB2::connect or DB::connect problem

Problems with the Windows version of XAMPP, questions, comments, and anything related.

XAMPP + PEAR: MDB2::connect or DB::connect problem

I'm using XAMPP under windows and everything seems working. I can access my database via phpmyadmin or even with mysql_connect() in php.
The problem is that I like to use the MDB2 or DB module of PEAR. But when I'm trying to connect he gives me all the time a 'not found'-error.
This is my code:
Code: Select all
<?php
\$db_type='mysql';
\$db_host='localhost';
\$db_database='allesinhout';

require_once("../../php/pear/MDB2.php");

\$connection =& MDB2::connect(\$dsn, array());
if (MDB2::isError(\$connection)){
die("Could not connect to the database: <br />".MDB2::errorMessage(\$connection));
}
?>

The problem has to be with the path. My localhost is at C:\Program Files\xampp\htdocs\ and i'm calling this file from http:\\localhost\allesinhout\index.php
The database itself is not in at C:\Program Files\xampp\htdocs\ but somewhere in C:\Program Files\xampp\mysql\ I think. Could this be the problem, and if it is, how can I solve it.

[/code]
bfl

Posts: 4
Joined: 10. February 2007 01:42

A hint for future questions:
Allways post complete error messages (copy 'n paste)

Code: Select all
require_once("../../php/pear/MDB2.php");

This should be:
Code: Select all
require_once 'MDB2.php';

http://pear.php.net/manual/en/package.d ... p#AEN34094
Wiedmann
AF Moderator

Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Thanks Wiedmann for the quick response.

First what you told me about the error:
This is the complete error, the only print is "Could not connect to the database: not found' which means MDB2::isError(\$connection) is false.

What you told me about require_once doesn't seem to work because then i get this warning:
Warning: require_once(MDB2.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\allesinhout\connect.php on line 21

Fatal error: require_once() [function.require]: Failed opening required 'MDB2.php' (include_path='.;C:\Program Files\xampp\smarty\libs') in C:\Program Files\xampp\htdocs\allesinhout\connect.php on line 21

What smarty has to do with this I don't understand, but this is not the main-problem here I think.
Any other idea?
bfl

Posts: 4
Joined: 10. February 2007 01:42

Fatal error: require_once() [function.require]: Failed opening required 'MDB2.php' (include_path='.;C:\Program Files\xampp\smarty\libs') in C:\Program Files\xampp\htdocs\allesinhout\connect.php on line 21

You have changed the "include_path" in "php.ini"? (You should restore the original.)

Code: Select all
\$connection =& MDB2::connect(\$dsn, array());

The second parameter is optional:
Code: Select all
\$connection =& MDB2::connect(\$dsn);

Code: Select all
if (MDB2::isError(\$connection)){
die("Could not connect to the database: <br />".MDB2::errorMessage(\$connection));
}

from the manual (link above), try this code:
Code: Select all
if (PEAR::isError(\$connection)) {
die('Could not connect to the database: <br />'.\$connection->getMessage());
}

?>
Wiedmann
AF Moderator

Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

The ini-file doesn't make a difference ( i need this also to work with smarty and which has never gave any problem). But to be sure I've tried it, with the excepted outcome.
I'm almost sure it has to do something with the path. Isn't there a place where I can change the path. Because if you want to work with phpmyadmin you also have to change this, maybe is this something similar?
bfl

Posts: 4
Joined: 10. February 2007 01:42

( i need this also to work with smarty and which has never gave any problem).

In this case append the smarty path and don't replace the original:
Code: Select all
include_path = ".;C:\Program Files\xampp\php\pear\;C:\Program Files\xampp\smarty\libs\"

OK. MDB2 use drivers for each database. And the driver for MySQL is not installed.

Open a command prompt (cmd.exe):
Code: Select all
cd "C:\Program Files\xampp\php"
pear install MDB2_Driver_mysql

Because if you want to work with phpmyadmin you also have to change this,

Sorry, don't understand this. You must not change paths(?) to work with phpMyAdmin...
Wiedmann
AF Moderator

Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Sorry, don't understand this. You must not change paths(?) to work with phpMyAdmin...