html - Fatal Error in PHP OOP Login Registration System -


i trying make user login registration system.all things going when trying insert fatal error , says

fatal error: call member function prepare() on non-object in c:\xampp\htdocs\loginregister\loginregistration\functions.php on line 11

i have searched , find topic said database variable should global .but not work me.can tell me problem?

thanks in advanced.

here config.php file.

 <?php   class databaseconnection{    public function __construct(){     try{         $db = new pdo('mysql:host=localhost;dbname=phplogin', 'root', '');     }     catch (pdoexception $e){         die("error database connection:".$e->getmessage());     }   }  }   ?> 

and here functions.php file.

 <?php   require "config.php";     class loginregistration{    function __construct(){     $database = new databaseconnection(); } public function resigteruser($username, $password, $name, $email, $website){     global $db;      $query = $db->prepare("select id users username = ? ,  email = ?");     $query->execute(array($username, $email));     $num = $query->rowcount();      if($num == 0){         $query = $db->prepare("insert users (username, password, name, email, website) values (?, ?, ?, ?, ?)");         $query->execute(array($username, $password, $name, $email, $website));         return true;      }     else{         return print "<span style='color:#e53d37'>error... username/email exist!</span>";      }    }  }   ?> 

change config code this

<?php  class databaseconnection{    public function __construct(){     try{         global $db;         $db = new pdo('mysql:host=localhost;dbname=phplogin', 'root', '');     }     catch (pdoexception $e){         die("error database connection:".$e->getmessage());     }   }  }   ?> 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -