Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $username = 'dbuser';
- $password = 'dbpass';
- $db_name = 'dbname';
- $table_name = 'tablename';
- $db_conn = mysql_connect($host, $username, $password) or die('Error: Could not connect.');
- mysql_select_db($db_conn, $db_name) or die('Error: Could not select database.');
- $result = mysql_query($db_conn, "SELECT * from " . $table_name) or die('Error: Could not query.');
- $json = array();
- if (mysql_num_rows($result)) {
- while ($row = mysql_fetch_array($result, mysql_ASSOC)) {
- $json['rawData'][] = $row;
- }
- }
- // for debug
- //echo json_encode($json, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
- // for production
- echo json_encode($json, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
- mysql_close($db_conn);
- ?>
Add Comment
Please, Sign In to add comment