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

Postby bfl » 10. February 2007 02:01

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';
$db_username='root';
$db_password='*****';
$dsn="$db_type://$db_username:$db_password@$db_host/$db_database";

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.

Thanks in advance
[/code]
bfl
 
Posts: 4
Joined: 10. February 2007 01:42

Postby Wiedmann » 10. February 2007 02:10

he gives me all the time a 'not found'-error.

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: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby bfl » 10. February 2007 02:16

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

Postby Wiedmann » 10. February 2007 02:45

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: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby bfl » 10. February 2007 02:57

The only difference it makes is that the error is "MDB2 Error: not found" instead of only "not found"
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

Postby Wiedmann » 10. February 2007 03:24

( 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\"


the error is "MDB2 Error: not found"

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 upgrade MDB2
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: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby bfl » 10. February 2007 05:27

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

My fault, was thinking about the password :oops:

But I've done the upgrade and installation of the mysql driver like you told me and everything works perfect now. Thanks a lot for the help, without your help I would be still searching!
bfl
 
Posts: 4
Joined: 10. February 2007 01:42


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 139 guests