Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $method = "GET";
- $str="";
- if($_SERVER["REQUEST_METHOD"]== $method)
- {
- $servername = "localhost";
- $username = "root";
- $password = "pranay";
- $dbname = "myDB";
- $str = $_GET['q'];
- // echo $qry;
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $qry = "SELECT firstname, lastname FROM LoginPDO where firstname like '%$str%'; ";
- $stmt = $conn->prepare($qry);
- // $stmt->bindParam(":querystring", $str);
- $stmt->execute();
- // echo $stmt->rowCount();
- // echo $stmt->debugDumpParams();
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- if($result){
- $results = $stmt->fetchAll();
- header('Content-Type: application/json');
- echo json_encode($results);
- }else
- echo " no resutl fodd";
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- }
Add Comment
Please, Sign In to add comment