Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    49
    Thanks
    8
    Thanked 2 Times in 2 Posts

    MDB2 Error: connect failed

    Hi, I am trying to set up the Pear MDB2 package, with the MySQL driver. I have installed all the necessary stuff and have tried to execute a simple query SELECT statement however I keep getting the message: -

    Code:
    MDB2 Error: connect failed
    PHP Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>test_mdb2</title>
    </head>

    <body>
    <?php

        
    require_once 'MDB2.php';
        
        
    $dsn = array(
            
    'phptype'  => 'mysql',
            
    'username' => 'user1',
            
    'password' => 'testpass1',
            
    'hostspec' => '127.0.0.1',
            
    'database' => 'people',
        );
        
        
    $options = array(
            
    'debug'       => 2,
            
    'portability' => MDB2_PORTABILITY_ALL,
        );
        

        
    // uses MDB2::factory() to create the instance
        // and also attempts to connect to the host
        
    $mdb2 MDB2::factory($dsn$options);
        
        if (
    PEAR::isError($mdb2)) {
            die(
    $mdb2->getMessage());
        }
        
        
    $res $mdb2->query('SELECT * FROM user');
        
            if (
    PEAR::isError($res)) {
            die(
    $res->getMessage());
            }
        
        
    // Disconnect
        
    $mdb2->disconnect();


    ?>
    </body>
    </html>
    Also the include_path need to have the file path to my pear folder? Currently it is set as .;C:\php\pear, since I am using WAMP do I need it for the C:\wamp\bin\php\pear folder?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    It doesn't look to me like you have a filepath issue, otherwise you should see errors referring to undeclared classes. You can double check by making sure your error reporting is open:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    I personally never use pear extensions since there is no guarantee that it will be available. Why not use a PDO instead of an MDB2?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •