Kodumu PDO'yu ekleme sırasında hata

0 Cevap php

I have connection.php file where i am initializing PDO in the $db. And i want to check this validation in the User.php which i include after connection.php. but it is giving me error .

try {
    $db = new PDO("mysql:dbname=$db_name;host=$db_host", $db_username,$db_password);
    echo "PDO connection object created";
}
catch(PDOException $e){
    echo $e->getMessage();
}

How can i validate this code by executing PDO. How i will pass the PDO to the User Class..

 Fatal error: Call to a member function query() on a non-object in /var/www/youngib/rahul/yapi/user.php on line 41

    $sql="select * from users where email='$this->email'";
            $rs=$db->query($sql);
            if(mysql_num_rows($rs)>0){
                $msg=geterrormsg(4);
                    //email already exist
                echo $msg= "{   'success': 'false','msg':'$msg'     ,'error_code':'4'       }";
                return false;
            }

Lütfen Yardım.

Teşekkürler.

0 Cevap