Jump to content

Recommended Posts

I have a site, up and running on the internet and want to run it locally. On my Mac I have Zend CE and can access my database with mysqli without a problem. The existing site uses Pear MDB2 to access the database. So, I installed MDB2 on my local machine and still couldn't access the database through the MDB2 code that works on the web server. I added an array to try to open the database connection on port number 10088 but that doesn't make any difference. I am new to Pear and MDB2. Any help appreciated.

 

To illustrate the problem I have created code that just opens the database directly and then fails with MDB2. Since it works in the first case, the database, username, etc. are all working.

<?php

ini_set("display_errors", "1");
error_reporting(-1);

ini_set('include_path', ini_get('include_path') . ':/home/davidann/php'.':/usr/local/zend/bin');

//Mysqli direct
include_once('setUnamePass.php');
$link = mysqli_connect("localhost", DBUSER, DBPASS, DATABASE) or die("Unable to connect!");
echo 'Success using mysqli directly';
$result=  mysqli_close($link);

//MDB2
include_once('MDB2.php');
define('DB_DSN', 'mysqli://'.DBUSER.':'.DBPASS.'@localhost/'.DATABASE);
class valuation {
public function __construct() {
		//open database connection
                //$options = array(
                  //  'port' => 10088,);
		$this->db_connection = MDB2::connect(DB_DSN);
		if (PEAR::isError($this->db_connection)) {
			exit($this->db_connection->getMessage());
		}
		
		//set fetch mode to associative
		$this->db_connection->setFetchMode(MDB2_FETCHMODE_ASSOC);
	}
}
$valuation = new valuation();
?>

The output is as follows:

Success using mysqli directly
Strict Standards: Declaration of MDB2_Driver_Common::raiseError() should be compatible with that of PEAR::raiseError() in /usr/local/zend/bin/MDB2.php on line 990

Strict Standards: Non-static method MDB2::connect() should not be called statically, assuming $this from incompatible context in /usr/local/zend/apache2/htdocs/NewFolder/NewFolder/ezvaluation2/www/ezvaluation.com/valuation/testdbopen.php on line 22

Strict Standards: Non-static method MDB2::factory() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 433

Strict Standards: Non-static method MDB2::parseDSN() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 376

Strict Standards: Non-static method MDB2::loadClass() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 385

Strict Standards: Non-static method MDB2::classExists() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 327

Strict Standards: Non-static method MDB2::fileExists() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 335

Strict Standards: Non-static method MDB2::raiseError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 340

Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 574

Strict Standards: Non-static method MDB2::errorMessage() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 972

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 743

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 386

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/bin/MDB2.php on line 434

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/local/zend/apache2/htdocs/NewFolder/NewFolder/ezvaluation2/www/ezvaluation.com/valuation/testdbopen.php on line 23
MDB2 Error: not found
Link to comment
https://forums.phpfreaks.com/topic/284534-using-pear-mdb2-and-mysqli/
Share on other sites

Looking at the pear project page for MDB2 it is no longer being maintained and is not compatible with the latest versions of PHP5. If your project requires this library then you need to downgrade PHP to an earlier version or upgrade your PHP app to use a different database api such as PDO, or MySQLi

Edited by Ch0cu3r

Two problems with your code.

 

1:

Non-static method MDB2::connect() should not be called statically
$this->db_connection = MDB2::connect(DB_DSN);
2:

Non-static method PEAR::isError() should not be called statically
if (PEAR::isError($this->db_connection)) {
Try fixing those (you probably want instances of those two objects) and see if that resolves all your problems - and makes all those Strict warnings go away.

Thank you Ch0cu3r. I will replace the MDB2 code with standard mysqli. I am much more comfortable with procedural style rather than oo. I have a concern that I will cause problems if I do the database operations in procedural style while the rest of the code is oo but can't think of any particular issue. Is there something I'm missing?

 

requinix: I started to try t figure out how to fix the static methods (other than to change the error reporting level) but it looks like I can't based ob the answer here: http://stackoverflow.com/questions/19248503/non-static-method-peariserror-should-not-be-called-statically

 

FWIW, I think that the problem extends beyond the warnings. It is the last line

MDB2 Error: not found

that makes me believe MDB2 failed to connect to the database.  When I installed MDB2 I failed to install the mysqli driver, which reading the documentation I see I also needed to do. http://pear.php.net/manual/en/package.database.mdb2.intro.php However, trying to install the driver fails

% sudo ./bin/PEAR install MDB2#mysqli
WARNING: "pear/Console_Getopt" is deprecated in favor of "pear/Console_GetoptPlus"
Skipping package "pear/MDB2", already installed as version 2.4.1
downloading PEAR-1.9.4.tgz ...
Starting to download PEAR-1.9.4.tgz (296,332 bytes)
.............................................................done: 296,332 bytes

Warning: mkdir(): File exists in System.php on line 285

Warning: mkdir(): Not a directory in System.php on line 285
ERROR: failed to mkdir /usr/local/zend/bin/PEAR/ChannelFile

and so I'm throwing up my hands and going to put up the time in to completely rip out MDB2 since it is not being maintained.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.