Results 1 to 7 of 7

Thread: [RESOLVED] PDO connection caching !!!

  1. #1
    Addicted Member
    Join Date
    Feb 10
    Location
    Damascus - Syria
    Posts
    133

    Resolved [RESOLVED] PDO connection caching !!!

    hi

    I have mad my website locally and it works fine, but when I upload it I get this error message:

    Fatal error: Call to a member function fetch() on a non-object in /home/rdisast/public_html/class.php on line 63

    for debugging, I have changed the password of db connection to a wrong password, but I didn't get "unable to connect" message, the same error appears

    is it possible that this is cache or something else?
    Last edited by fjober; Aug 27th, 2012 at 11:44 AM.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: PDO connection caching !!!

    I think, your query might have failed and have returned a FALSE, instead of the resultset. So, you might have been trying to fetch rows from this without checking whether the query have returned a resultset or a FALSE value.

    Example:
    Code:
    $r = $db->query("SELECT something FROM shelf");
    if( $r === false )
    {
      echo 'Sorry, the query failed!';
    }
    else
    {
      // fetch rows...
    }

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Addicted Member
    Join Date
    Feb 10
    Location
    Damascus - Syria
    Posts
    133

    Re: PDO connection caching !!!

    thanks for replay akhileshbc

    yes, it returns false, but why does it return false while I have tested the sql statement at phpMyAdmin and it works !!!

    here is my code :

    PHP Code:
    <?php
    class myClass
    {
        public 
    $dbh;
        public function 
    __construct()
        {
            
    $this->dbh = new PDO('mysql:host=localhost;rdisast_db''rdisast_user''$+f~65G@e');
        }
        public function 
    getFieldData($tableName$fieldNumber$value$columnName)
        {
            
    $sth $this->dbh->query("SELECT * FROM `$tableName` WHERE `$columnName`='$value'");
            
    $fetch $sth->fetch();
            return 
    $fetch[$fieldNumber];
        }
        public function 
    preLang($httpReferer)
        {
            
    $l '';
            
    $explodedReferer explode('/',$httpReferer);
            
    $c count($explodedReferer);
            for (
    $i 0$i $c$i++) {
                if (
    $explodedReferer[$i] == 'du' || $explodedReferer[$i] == 'en') {
                    
    $l $explodedReferer[$i];
                    break;
                }
            }
            if (
    $l == '') {
                
    $l $this->getFieldData('settings','dl','1','id');
            }
            return 
    $l;
        }
    }
    $obj = new myClass;
    if (!
    $_GET['lang']) {
        
    $language $obj->preLang($_SERVER['HTTP_REFERER']);
    } else {
        
    $language $_GET['lang'];
    }
    if (
    $language == 'du') {
        
    $lKey 2;
    } else {
        
    $lKey 1;
    }
    $tr = array();
    $gT $obj->dbh->query('SELECT * FROM `translate`');
    while(
    $t $gT->fetch()) {
        
    $tr[$t['code']] = $t['word'.$lKey];
    }

    ?>
    the first execution of a sql statemnt is in getFieldData() function, and when I debricated it, the error become at the line of while loop "while($t = $gT->fetch()) "

    I think the problem in in db connection, but I am sure of the username and password, and permissions for this user
    Last edited by fjober; Aug 27th, 2012 at 09:23 PM.

  4. #4
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: PDO connection caching !!!

    try
    PHP Code:
    print_r($obj->$dbh->errorInfo()) 

  5. #5
    Addicted Member
    Join Date
    Feb 10
    Location
    Damascus - Syria
    Posts
    133

    Re: PDO connection caching !!!

    thank you penagate
    oh !!!!
    Fatal error: Cannot access empty property in /home/rdisast/public_html/class.php on line 260

  6. #6
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: PDO connection caching !!!

    What's line 260?
    Put that code after the query that fails.

    For example:
    PHP Code:
    $sth $this->dbh->query("SELECT * FROM `$tableName` WHERE `$columnName`='$value'");
    if (
    $sth === null)
        
    print_r($this->dbh->errorInfo()); 

  7. #7
    Addicted Member
    Join Date
    Feb 10
    Location
    Damascus - Syria
    Posts
    133

    Re: PDO connection caching !!!

    ok ,
    this is the result
    Array ( [0] => 3D000 [1] => 1046 [2] => No database selected )

    the line 260 is located in getFieldData() which is $fetch = $sth->fetch();

    solved: error syntax of creating PDO connection.

    thank you guys
    Last edited by fjober; Aug 27th, 2012 at 10:45 PM.

Posting Permissions

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