Created
December 30, 2016 07:29
-
-
Save manishkpr/b450c602d11a3ceb3139464a8ed35377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
//-------------------------------------------------------------------------- | |
// Example php script for fetching data from mysql database | |
//-------------------------------------------------------------------------- | |
$host = "localhost"; | |
$user = ""; | |
$pass = ""; | |
$databaseName = ""; | |
$tableName = "suggestions"; | |
//-------------------------------------------------------------------------- | |
// 1) Connect to mysql database | |
//-------------------------------------------------------------------------- | |
$con = mysql_connect($host,$user,$pass); | |
$dbs = mysql_select_db($databaseName, $con); | |
$name=$_REQUEST['name']; | |
//-------------------------------------------------------------------------- | |
// 2) Query database for data | |
//-------------------------------------------------------------------------- | |
$result = mysql_query("SELECT * FROM $tableName where name like '$name%%'"); //query | |
//$array = mysql_fetch_row($result); //fetch result | |
$rows = array(); | |
while($r = mysql_fetch_assoc($result)) { | |
$rows['results'][] = $r; | |
} | |
//-------------------------------------------------------------------------- | |
// 3) echo result as json | |
//-------------------------------------------------------------------------- | |
echo json_encode($rows); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment