I'm quite new to PDO and OOP. After, I try to execute the code given below , I get this output :- Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\Mine\OOPs\pdo progs\function.php on line 20. Thanks.
<?php
class main
       {
         public function __construct()
       { 
        $obj=new PDO("mysql:host=localhost;dbname=arnob-pdo",'root','');    
       }    
        public function reg()   
    {
        global $obj;
        $name=$_POST['name'];
        $email=$_POST['email'];
        $pass=$_POST['pass'];
                $sql=$obj->query("insert into memo set                                                            
                name='".$name."',email='".$email."',pass='".$pass."'");
        if($sql)
            {
             ?>
             <script type="text/javascript"> 
             alert("WELCOME <?php echo $_POST['name']; ?> to Memo"); 
             </script>
             <?php  
            }
             else echo 'Registration Failure';
       }        
        }
       $main=new main;
       ?>
        index.php:
        <?php require('function.php'); 
        if (isset($_POST['submit']))
         {  
      $exe=$main->reg();
      echo $exe; 
         } 
         ?>
with a form for submit.
 
     
    