Skip to content

Instantly share code, notes, and snippets.

@modond
Created November 23, 2012 07:59
Show Gist options
  • Select an option

  • Save modond/4134448 to your computer and use it in GitHub Desktop.

Select an option

Save modond/4134448 to your computer and use it in GitHub Desktop.
<?php
$host="localhost"; //replace with your hostname
$username="database_example"; //replace with your username
$password="Password"; //replace with your password
$db_name="MyMovies"; //replace with your database
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name") or die ("cannot select DB");
$sql = "select * from BestMovies"; //replace with your table name
$result = mysql_query($sql);
$json = array();
if(mysql_num_rows($result)){while($row=mysql_fetch_row($result)){
$json[]=$row;
}
}
mysql_close($db_name);
echo json_encode($json);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment