Select With Parameter PHP OOP



<?php
class YourTube {
    private $DbCon = null;
    public function __construct() {
        $this->DbCon = new PDO('mysql:host=localhost;dbname=google', 'root', '');
    }
    public function SqlSelect() {
        $Sql = "SELECT * FROM emp WHERE id=:id AND fname=:fn";
        $stmt=$this->DbCon->prepare($Sql);
        $stmt->execute(array(':id'=>1,':fn'=>'Anil'));
        $data=array();
        while($row=$stmt->fetch()){
           $data[]=$row;
           // print_r($row);
        }
       return $data;
    }
}

<?php
require_once './youtube.php';
$Sql=new YourTube();
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>PHP My MVC Framework</title>
    </head>
    <body>
       <?php
       foreach ($Sql->SqlSelect() as $post){
           print $post['id'].' '.$post['fname'].' '.$post['age'].' '.$post['salary'].'<br/>';
       }
       ?>
    </body>
</html>

Out Put:-
1 Anil 18 30000.40
Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment