Last active
December 28, 2015 02:09
-
-
Save johnbocook/7425352 to your computer and use it in GitHub Desktop.
Mysql query in PHP converted to json feed and displayed on page.
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 | |
//change these settings | |
$dbhost = ""; | |
$dbusername = "": | |
$dbpassword = "": | |
$dbname = ""; | |
$dbtable = ""; | |
//connect to database and grab the data | |
$connection = mysql_pconnect($dbhost, $dbusername, $dbpassword) or die("Could not connect"); | |
mysql_select_db($dbname) or die("Could not find database"); | |
$data = array(); | |
$query = mysql_query("SELECT * FROM " . $dbtable); | |
while($row = mysql_fetch_object($query)) { | |
$data[] = $row; | |
} | |
//output the data as a JSON feed | |
echo '{"JsonFeed":' . json_encode($data) . '}'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment