Advertisement
colmulhall

Untitled

Apr 2nd, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(mysqli_num_rows($result))
  21.     {
  22.             while($row = mysqli_fetch_assoc($result))
  23.             {
  24.                 $json['events'][] = $row;
  25.             }
  26.             echo json_encode($json);
  27.     }
  28.     mysqli_close($con);
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement