ConnectPHPWithMySQL.php

<!DOCTYPE html> <html> <head> <title>Learning Database</title> </head> <body> <h1>MySQL with PHP</h1> <?php $host = "localhost"; $username = "root"; $password = "root"; $database = "wtdb"; $connection = mysqli_connect($host, $username, $password, $database); if (!$connection) { echo "Database connection failed"; } $sql = "SELECT * FROM `users` WHERE `id` = '100'"; $result = mysqli_query($connection, $sql); $numOfRows = mysqli_num_rows($result); echo $numOfRows."<br />"; if ($numOfRows == 0) { echo "There are no records yet."; } while ($row = mysqli_fetch_assoc($result)) { echo "Welcome ".$row['username']; echo "<br />"; } ?> </body> </html>
This code allows to connect the PHP with MYSQL, if you have database named "wtdb" .

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.