This code will allow you to connect a Database in MySQL in PHP programming language. There are basically two ways you want to access your database. One is to your local server other one is online server.
Method 1: Via local server
This method allows you to connect to your local server
<?php
//Change your information according to your server$username = "your_username";
$password = "your_password";
$database = "your_database_name";//Creating the connection
$connection = mysqli_connect("localhost",$username,$password) or die("Connection not successful.");
//Selecting the database you want to use in your page
mysqli_select_db($connection, $database) or die("Database selection failed.");//Your content regarding MySQL lies here
//Closing your connection
mysqli_close($connection);
?>
Method 2: Via online server
If your server is online use this method but change the “example.com” according to your server.
<?php
//Change your information according to your server$username = "your_username";
$password = "your_password";
$database = "your_database_name";//Creating the connection
$connection = mysqli_connect("example.com",$username,$password) or die("Connection not successful.");
//Selecting the database you want to use in your page
mysqli_select_db($connection, $database) or die("Database selection failed.");//Your content regarding MySQL lies here
//Closing your connection
mysqli_close($connection);
?>
Enjoy…
Incoming search terms:
- mysqli_connect di eclipse dengan php (1)