PHP And MySQL Code : How To Connect Php And MySQL Database And Display Data.
In this Php Tutorial we will Learn How To Connect PHP With MySQL Database And Show Database Table Data using MySQLI .
I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .
- PhpMyAdmin .
- MySQL Database .
Php Source Code:
<?php
// create a connection between php and mysql database
$hostname = "localhost";
$username = "root";
$password = "";
// your database name
$databaseName = "test_db";
// create The connection
$connect = mysqli_connect($hostname, $username, $password);
mysqli_select_db($connect, $databaseName);
// the mysql query
$query = "SELECT * FROM `users`";
$result = mysqli_query($connect, $query);
// using while loop to dispaly data from database
while($row = mysqli_fetch_array($result))
{
echo "$row[0] - $row[1] - $row[2] - $row[3]<br>";
}
// free your result
mysqli_free_result($result);
// close the connection
mysqli_close($connect);
// create a connection between php and mysql database
$hostname = "localhost";
$username = "root";
$password = "";
// your database name
$databaseName = "test_db";
// create The connection
$connect = mysqli_connect($hostname, $username, $password);
mysqli_select_db($connect, $databaseName);
// the mysql query
$query = "SELECT * FROM `users`";
$result = mysqli_query($connect, $query);
// using while loop to dispaly data from database
while($row = mysqli_fetch_array($result))
{
echo "$row[0] - $row[1] - $row[2] - $row[3]<br>";
}
// free your result
mysqli_free_result($result);
// close the connection
mysqli_close($connect);
///////////////OUTPUT:
2 comments
commentsplease you can see this at Connect mysqli in php verry thank admin
Replyyou are best bro
Reply