Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.     $db = mysql_connect("localhost","nav","Austin1997$$#@");
  3.     if (!$db) {
  4.         die('Could not connect to db: ' . mysql_error());
  5.     }
  6.  
  7.     //Select the Database
  8.     mysql_select_db("testing_nav",$db);
  9.    
  10.     //Replace * in the query with the column names.
  11.     $result = mysql_query("select * from testingtable", $db);  
  12.    
  13.     //Create an array
  14.     $json_response = array();
  15.    
  16.     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  17.         $row_array['test'] = $row['test'];
  18.         $row_array['test2'] = $row['test2'];
  19.         $row_array['test3'] = $row['test3'];
  20.         array_push($json_response,$row_array);
  21.     }
  22.     echo json_encode($json_response);
  23.    
  24.     //Close the database connection
  25.     fclose($db);
  26.  
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement