简体   繁体   中英

php - Call to a member function prepare() on a non-object in

I get this error:

Fatal error: Call to a member function prepare() on a non-object in /home/folder/public_html/includes/name.php on line 1768  

This is the function:

function _FC_GET($typ, $data, $username){

            global $dbh;
            $stmt = $dbh->prepare("SELECT * FROM stats_clicks WHERE typ=:typ AND user=:username AND data=:data LIMIT 1;");
            $stmt->bindParam(':typ', $typ);
            $stmt->bindParam(':username', $username);
            $stmt->bindParam(':data', $data);
            try {
            $stmt->execute();
            }
            catch(PDOException $e) {
                die( _OP_ERROR($e->getMessage(), __FILE__ ,__LINE__) );     
            }

            $QUERY_DAT = $stmt->fetchAll();
            return empty($QUERY_DAT['value']) ? 0 : $QUERY_DAT['value'];

        }

And this is line 1768 :

$stmt = $dbh->prepare("SELECT * FROM stats_clicks WHERE typ=:typ AND user=:username AND data=:data LIMIT 1;");

I can't seem to find what is causing this. I use the $dbh-prepare(); statement in other functions in the same file.

$dbh is not defined at that line. Check where you create the object $dbh if it is before the line 1768 or it is not in any condition which is not fulfilled.

Try this :

Look at here

Probably the cause of your connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM