1<?php
2 /* Connect to your database */
3 $con = mysqli_query("hostname", "username", "pwd", "database");
4 /* Select Columns from table*/
5 $sql = "SELECT * FROM `TABLE`";
6 /* Query your SQL code to SQLDatabase */
7 $result = mysqli_query($con, $sql);
8 /* Find rows in table*/
9 $check = mysqli_num_rows($result);
10 if($check > 0){
11 while($data= mysqli_fetch_assoc($result)){
12 /* Print all of your data*/
13 echo $data["ColName"];
14 }
15 }
16?>
1<?php
2$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
3
4/* check connection */
5if ($mysqli->connect_errno) {
6 printf("Connect failed: %s\n", $mysqli->connect_error);
7 exit();
8}
9
10$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
11
12if ($result = $mysqli->query($query)) {
13
14 /* fetch associative array */
15 while ($row = $result->fetch_assoc()) {
16 printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
17 }
18
19 /* free result set */
20 $result->free();
21}
22
23/* close connection */
24$mysqli->close();
25?>
1$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
2$result = mysqli_query($con, $sql);
3
4
5/*MYSQLI_ASSOC
6MYSQLI_NUM (this is default)
7MYSQLI_BOTH
8 */
9// Fetch all
10mysqli_fetch_all($result, MYSQLI_ASSOC);
11