0
How to connect MySQL database to php?
Im having hard time to connect my database to php.
3 odpowiedzi
+ 2
<?php
$serverName = "localhost";
$userName = "root";
$password ="123";
$conn = mysqli_connect($serverName, $userName, $password);
if($conn) {} else {
echo "Database connection error! " . mysqli_connect_error($conn);
echo "<br>";
die("Program failed... ");
}
?>
/*Remember to replace server name, username and password with correct ones for your own machine. Also if you do not have a password just omit it.
*/
+ 2
A very comprehensive tutorial here
https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/17
+ 1
In simple way
$connection = mysqli_connect($host, $user, $password, $database)
or die (' Error in connect DB ' );
Don't forget to close connection when you finish
mysqli_close($connection);