To perform database operations like insert, read, update, delete operations we need the database connection.
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('myfirstdatabase');
?>
You can establish the database connection using above simple code.
mysqli_connect('ServerName', 'Username', 'Password', 'DatabaseName');
For mysqli function we have to pass all four parameters into the mysqli_connect() function.
Database Name ⇨ myfirstdatabase
<?php
$conn = mysqli_connect('localhost', 'root', '', 'myfirstdatabase');
?>
We can include more than one different connection of database into the single PHP page. For example . There are two following database users. • USERA • USERB For USERA we don't want that he should have access to update the database, and for USERB we want to set that he should have all database's operations access. So in this case we can make two connection within the same PHP file. Note. We can set the user access setting or privileges setting from database setting in Phpmyadmin.
<?php
$usera_connection = mysqli_connect('localhost', 'usera','12345', 'myfirstdatabase');
$userb_connection = mysqli_connect('localhost', 'userb','12345', 'myfirstdatabase');
?>