Accessing Php page with data from MySql

peter tests

test no = 15

part 1 --- php
part 2 --- MySql
                $servername = "";
                $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);
                while($row = mysqli_fetch_assoc($result)) {
                    echo  "" . $row["dog_name"] . "" . $row["dog_age"]. "";
part 3 --- development
            step 1, setup
            - add a new empty php file as below
            - add it in your server, test it in a browser
within php tags, $test_no = 2; <!DOCTYPE html> <html lang="en"> <head>my header</head> <body> within php tags, echo $test_no; </body> </html>
            - 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
            left join
            - 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.
part 4 --- lab, access mysql data - LEFT JOIN
house dogs
dog namedog age