Search form sample pattern I've just started to practice coding in OOP and just wanted to ask if my code's pattern is correct.  I need your comments or suggestions so I can improve it.

sample_class.php:

&lt;?php
$host = 'localhost';
$db = 'sample_db';
$user = 'sample_user';
$pass = 'sample_password';
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
$conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);  

Class MySearchClass {

    public function __construct(PDO $conn) {
        $this-&gt;pdo=$conn;  
    }

    public function search_name($keyword){

        $query = "SELECT * FROM table WHERE name = '$keyword'";  
        $result = $this-&gt;pdo-&gt;prepare($query);  
        $result -&gt;execute();  

        return $result;
    }

    public function view_all(){
        $query = "SELECT * FROM table";  
        $result = $this-&gt;pdo-&gt;prepare($query);  
        $result -&gt;execute();  

        return $result;
    } 
}


search_form.php:

&lt;?php  
include('sample_class.php');
$search= new MySeachClass($database_connection);

if (isset($_POST['submit'])){  
    $keyword = $_POST['keyword'];
    $go_search = $search-&gt;search_name($keyword);

    $data = $go_search-&gt;fetchAll(PDO::FETCH_ASSOC);   

    foreach($data as $row){
        echo $row['name'];  
        echo other rows....
    }  

}else{
    $view = $search-&gt;view_all();
    $data = $view-&gt;fetchAll(PDO::FETCH_ASSOC);  

    foreach($data as $row){
        echo $row['name'];  
        echo other rows....
    }
}

&lt;form action="" method="POST"&gt;  
&lt;input type="text" name="keyword"&gt;  
&lt;input type="submit" name="search"&gt;
&lt;/form&gt;
Here's a recommendation to bind parameters correctly. This sort of thing is used to prevent against SQL injection attacks.

$query = "SELECT * FROM table WHERE name = :keyword";  
$statement = $this-&gt;pdo-&gt;prepare($query);
$statement-&gt;bindParam(':keyword', $keyword, PDO::PARAM_STR);
$result $statement-&gt;execute();  


Read more about PDOStatement#bindParam here