Skip to content

Instantly share code, notes, and snippets.

@vitqst
Created September 10, 2015 23:20
Show Gist options
  • Save vitqst/31ac8aa112fcd1ee216e to your computer and use it in GitHub Desktop.
Save vitqst/31ac8aa112fcd1ee216e to your computer and use it in GitHub Desktop.
<?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