Skip to content

Instantly share code, notes, and snippets.

@mustafaakin
Created March 18, 2012 22:41
Show Gist options
  • Save mustafaakin/2083326 to your computer and use it in GitHub Desktop.
Save mustafaakin/2083326 to your computer and use it in GitHub Desktop.
Basic-PHP MySQL Code
<?php
$host = "localhost";
$username = "root";
$password = "123";
$db_name = "test";
$db=mysql_connect($host, $username, $password) or die('Could not connect');
mysql_select_db($db_name, $db) or die('no db');
$sth = mysql_query("SELECT * FROM sample s");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
echo json_encode($rows);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment