Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('DB_SERVER', 'localhost');
- define('DB_USER', 'root');
- define('DB_PASSWORD', '');
- define('DB_NAME', '');
- if (isset($_GET['term'])){
- $return_arr = array();
- try {
- $conn = new PDO("mysql:host=".DB_SERVER.";port=3306;dbname=".DB_NAME, DB_USER, DB_PASSWORD);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare('SELECT title FROM news WHERE title LIKE :term');
- $stmt->execute(array('term' => '%'.$_GET['term'].'%'));
- while($row = $stmt->fetch()) {
- $return_arr[] = $row['title'];
- }
- } catch(PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- echo json_encode($return_arr);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement