0

How to connect MySQL database to php?

Im having hard time to connect my database to php.

24th Apr 2017, 11:06 PM
Trinugh
Trinugh - avatar
3 Respostas
+ 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. */
24th Apr 2017, 11:15 PM
weAreTheOne
weAreTheOne - avatar
24th Apr 2017, 11:22 PM
Calviղ
Calviղ - avatar
+ 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);
25th Apr 2017, 2:35 AM
‎علي فرعون‎
‎علي فرعون‎ - avatar