test no = 15
$servername = "xx.winhost.com"; ... $conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "SELECT t1.dog_name, t2.dog_age from dogs AS t1 LEFT JOIN dogs2 AS t2 on t1.dog_name = t2.dog_name;"; $result = mysqli_query($conn, $sql); mysqli_close($conn);
... while($row = mysqli_fetch_assoc($result)) { echo ""; } " . $row["dog_name"] . " " . $row["dog_age"]. "
step 1, setup - add a new empty php file as below - add it in your server, test it in a browser
- when testing in the browser, you see the html page from the response, - having the static html code - having the dynamic data prepared in the php code in the sever.
step 2, get data from mysql - For this page, the senario is as below: 1. client tier, client tier, request house dog data. 2. php web site tier, web tier, sent its db connection and its query to db tier. - PHP is a server-side scripting language, executes in the ser server. - You secifiy you database credential in php code, they will not be seen in web traffic. 3. db server tier, execute the query, send back the data. 4. php web site, prepare a html page from the db tier. - using php echo statment to insert dynamic data in ther html code 5. client tier, the page can be browsed.
dog name | dog age |
---|---|
Tairo | 6 |
Emi | 5 |
Joy | |
Lucky |