Home » Database » MDB2 » Bug #5028
PHP 4/5 constructor problems on windows systems
Details
| Submitted | 2005-08-08 19:55 UTC |
|---|---|
| From | alex at gengon dot de |
| Status | Bogus |
| Package | MDB2 |
| PHP Version | 5.0.4 |
| OS | Windows |
| Roadmaps | (Not assigned) |
Comments
[2005-08-08 19:55 UTC] alex at gengon dot de
Description:
------------
I´ve trying to use the MDB2 classes on my windows based dev. environment and found a bug in the constructor usage when developing 4/5 projects. With the 2.0.5 beta i have found
that when trying to connect to a DB the hole process failes.
The Browser replys only 'The document containes no data'.
I´ve found an improvement to fix the bug.
It´s quit simple just rewrite the __construct() on each
driver to the PHP 4 notation i.e. MDB2_Driver_mysql() and call the parent constructor with parent::MDB2_Driver_Common();
This solves the problem.
Only tested with the mysql.
Test script:
---------------
<?php
ini_set( 'include_path',
'pear/'.PATH_SEPARATOR.
ini_get('include_path')
);
require_once 'MDB2.php';
$dsn = "mysql://alex:alex@localhost/mdb2test";
$db =& MDB2::connect( $dsn );
if ( PEAR::isError( $db ) ) {
die ( __LINE__.$db->getMessage() );
} else {
echo "DB connection succeded!";
}
?>
Expected result:
----------------
Expected output
DB connection succeded!
when changing the the contruct things descripied above the
hole things rocks.
Actual result:
--------------
Browser alert
The document containes no data.
nothing else no die or backtrace()
[2005-08-08 20:43 UTC] alex at gengon dot de
This style of using mixture php4/5 notation is more
error-prone than writing it only in 4 notation. This
is maybe a future error source for other bugs.
So i think this will not be 'fixed' in a later release
or do i misunderstood???
yours
alex
[2005-08-08 21:18 UTC] alex at gengon dot de
Ah okay, your right it could be possible
that the problem will nest in a diffrent
part than the construct.
But the whole thing is this
when calling the MDB2_Driver_mysql __construct() in PHP5
it also calls the MDB2_Driver_Common() parent constructor automaticly and this will call the __construct() method once again and so on. this will ends in an recursive call.
i have tried it in diffrent scenarios on calling and this seems to be the point of the error.
I dont know why in other scenarios this will not be
occured but this seems to me very comprehensible why the problem is how it is.
And where is the advantage of using a not on classname dependent constructor???
I hope I have clarify my probs in detail, and btw. thx for your great work MDB2 is very nice.
yours
alex
[2005-08-09 14:32 UTC] david dot coallier at gmail dot com
Ok, I worked MDB2 with both php4 and php5 and so far didnt' have this problem.
The way we are calling the constructor in MDB2_Driver_Common is not wrong because you can see that the php4 constructor is calling the function $this->__construct() which is fine.
Just like this, that might be totally irrelevant, but did you try with the dsn array ?
so instead of this:
$dsn = "mysql://alex:alex@localhost/mdb2test";
try that:
$dsn = array(
'phptype' => 'mysql',
'hostspec' => 'localhost',
'username' => 'alex',
'password' => 'alex',
'database' => 'mdb2test'
);
Thanks :)
[2005-08-09 19:08 UTC] alex at gengon dot de
the dsn don´t matter it´s allways the same problem
an multi __construct() call. so far i dont know ;)
strange is that the
parent::__construct() call in in the mysyl driver
will call MDB2_Driver_Common() instead of __construct(), this is very strange.
for now i will use it with my constructor workaround, this works fine and maybe on a newer MDB2 release or PHP 5 release the problem is solved.
[2006-12-28 15:49 UTC] martin dot mesrsmid at sprace dot cz
I understand that this bug is closed but I just had the exactly same problem with MDB2 2.3.0 and PHP 5.1.4 on Debian linux with Apache (in my case php runs as cgi)
The parent constructor call in MDB2_Driver_mysql() hangs up the script no matter what is inside the parent constructor (I tried to play around with it a little). Solution that worked for me was to copy the parent constructor internal code (4 lines only) to MDB2_Driver_mysql() constructor and it works fine.