Advertisement
colmulhall

Untitled

Apr 2nd, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. <?php
  2.     $host="localhost";
  3.     $username="root";
  4.     $password="";
  5.     $db_name="park";
  6.  
  7.     // Create connection to the database
  8.     $con = mysqli_connect("$host", "$username", "$password", "$database");
  9.        
  10.         // Select database
  11.     mysql_select_db("$db_name")or die("cannot select DB");
  12.    
  13.     // Run an sql query to return data from the database
  14.     $sql = "select title from events";
  15.    
  16.     $result = mysqli_query($con, $sql);
  17.     $json = array();
  18.  
  19.     // Get each row of data from the database
  20.     if(mysql_num_rows($result))
  21.     {
  22.             while($row = mysql_fetch_assoc($result))
  23.             {
  24.                 $json['events'][] = $row;
  25.                
  26.             }
  27.             echo json_encode($json);
  28.     }
  29.     mysql_close($con);
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement