SHOW:
|
|
- or go back to the newest paste.
| 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)) |
| 20 | + | if(mysqli_num_rows($result)) |
| 21 | {
| |
| 22 | - | while($row = mysql_fetch_assoc($result)) |
| 22 | + | while($row = mysqli_fetch_assoc($result)) |
| 23 | {
| |
| 24 | $json['events'][] = $row; | |
| 25 | - | |
| 25 | + | |
| 26 | echo json_encode($json); | |
| 27 | } | |
| 28 | mysqli_close($con); | |
| 29 | - | mysql_close($con); |
| 29 | + |