SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: PEAR MDB2 Error

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PEAR MDB2 Error

    Hello folks,

    Does anyone know why I'm experiencing this error:

    Fatal error: Call to a member function setFetchMode() on a non-object in /xxx/functions.php on line 20

    The code in functions.php looks like this:
    PHP Code:
    function &db_connect() {
        
    set_include_path('/home/xxx/pear/lib/php/');
    //    echo ini_get("include_path");
    //    exit;
        
    require_once 'MDB2.php';
        
    PEAR::setErrorHandling(PEAR_ERROR_DIE);
        include(
    '../code/credentials.inc');
        
    $dsn "mysql://$db_user:$db_pass@$db_host/$db_name";
        
    $db MDB2::connect($dsn);
        if (
    PEAR::isError($db)) {
            
    $host  $_SERVER['HTTP_HOST'];
            
    $uri  rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
            
    $extra 'maintenance.php';
            
    header("Location: http://$host$uri/$extra");
            exit;
        }
        
    $db->setFetchMode(MDB2_FETCHMODE_OBJECT);
        return 
    $db;

    Running on a LAMP box with PHP5 and Apache 2.
    Worth mentioning is that before MDB2 I was running the old deprecated package DB without any problems. So basically I've just changed the DB:: to MDB2:: but that's all that should I need to do...

    EDIT: For some weird reason that error went away when I tried to edit the functions.php file again. Weird.

    Anyhow a new problem arised.. now I'm getting this error:

    Fatal error: Call to undefined function: MDB2_Driver_mysql::fetchAll(). in /home/xxx/pear/lib/php/MDB2.php on line 1921

    What gives? fetchAll() is a defined function isn't it?

  2. #2
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pcw View Post
    Anyhow a new problem arised.. now I'm getting this error:

    Fatal error: Call to undefined function: MDB2_Driver_mysql::fetchAll(). in /home/xxx/pear/lib/php/MDB2.php on line 1921

    What gives? fetchAll() is a defined function isn't it?
    What's the code that calls "fetchAll()"? Please include the db object instantiation code as well.
    Usually this means that the recordset is not really a recordset (may be a PEAR error object, or simply 'false'). Try doing
    PHP Code:
    var_dump($rs); 
    to see what's really in your recordset.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright the weird part is that I really don't know how to call fetchAll() .. in the previous version (DB) you called getAll like this:

    $sql = "SELECT * FROM Table";
    $result =& $db->fetchAll($sql, array(), DB_FETCHMODE_OBJECT);

    In this MDB2 version it's called fetchAll() and you call it like this:

    fetchAll( [int $fetchmode = MDB2_FETCHMODE_DEFAULT], [bool $rekey = false], [bool $force_array = false], [bool $group = false])

    But there is no argument that takes the $sql query in fetchAll() so I don't really get it at all :P

  4. #4
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $r_recordset $r_database->query($query);
    $a_results $r_recordset->fetchAll([method]); 
    Where $query is your query string (SELECT statement, etc.) and $r_database is your database object.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    miggl: thanks alot mate! that helped me out alot.. it's starting to work now silly me I couldn't find any reference in the pear documentation on how to call the query and fetchAll methods...

    however another question

    In DB when you retrieved a resultset (with fetchmode object) the field names were retrieved case sensitive from the sql query. But it appears as MDB2 converts all field names to lower case.

    Is there a way to get the field names case sensitive as in PEAR DB?

  6. #6
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by pcw View Post
    Is there a way to get the field names case sensitive as in PEAR DB?
    I'm not sure. What is the reason you want them case sensitive? The reason I pose that question is that normally you would want them to be all lower case, so that you don't have to worry about case when using keys. Besides, it forces you to use unique names for each field, cutting down on confusion.

    I guess the one reason I could see that it is causing a problem is that you are switching DBALs and now would have to rework all your db code. With that in mind (and you mentioned you couldn't find any good documentation) let me point you in this direction: MDB2 Documentation. I don't have the answer at this moment, but if I find something, I'll post here.

    Glad to hear you're back on your feet and got it running.

    Cheers,
    Mike

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    miggl: Exactly it's because I'm switching from DB to MDB2 and like I said in DB it retrieves all the field values case sensitively (like they're named in the database) and now I have to rewrite all the fields in my code to lowercase :P

    I've been using that documentation as well but it doesn't really cover alot.

    Thanks alot for your efforts in helping!

    Peter

  8. #8
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check this post out, where they talk about DB -> MDB2 portability in the comments: http://www.phpied.com/db-2-mdb2.

    Also, this manual page will help with setting portability flags: http://pear.php.net/manual/en/packag...ortability.php

    Good luck


Bookmarks

Posting Permissions

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