Skip to content

Instantly share code, notes, and snippets.

@ashumeow
Last active March 30, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashumeow/fe39b0f61f0354cb96839d9f2e737e1f to your computer and use it in GitHub Desktop.
Save ashumeow/fe39b0f61f0354cb96839d9f2e737e1f to your computer and use it in GitHub Desktop.
Connecting to MySQL database via PHP script
<?php
$host = '127.0.0.1';
$user = 'abc';
$pwd = 'abc';
$db = 'xyz';
$con = mysql_connect($host, $user, $pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$r=mysql_query("select * from class",$con);
while($row=mysql_fetch_array($r))
{
$cls[]=$row;
}
print(json_encode($cls));
mysql_close($con);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment