Created
September 10, 2015 23:20
-
-
Save vitqst/31ac8aa112fcd1ee216e 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 | |
//-------------------------------------------------------------------------- | |
// Example php script for fetching data from mysql database | |
//-------------------------------------------------------------------------- | |
$host = "localhost"; | |
$user = "root"; | |
$pass = "root"; | |
$databaseName = "ajax01"; | |
$tableName = "variables"; | |
//-------------------------------------------------------------------------- | |
// 1) Connect to mysql database | |
//-------------------------------------------------------------------------- | |
include 'DB.php'; | |
$con = mysql_connect($host,$user,$pass); | |
$dbs = mysql_select_db($databaseName, $con); | |
//-------------------------------------------------------------------------- | |
// 2) Query database for data | |
//-------------------------------------------------------------------------- | |
$result = mysql_query("SELECT * FROM $tableName"); //query | |
$array = mysql_fetch_row($result); //fetch result | |
//-------------------------------------------------------------------------- | |
// 3) echo result as json | |
//-------------------------------------------------------------------------- | |
echo json_encode($array); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment