Most application programs need to be connected to the database inorder to do some basic operations like saving and retrieving the user details / data.
In this video tutorial we illustrate, how we need to connect to MySQL server from PHP script.
Connecting to MySQL server
db.php
< ?php
$conn = mysql_connect('localhost','root','');
$db = mysql_select_db('database_name', $conn);
?>
Include this file in all other files which needs to communicate with this database database_name
< ?php
include_once('db.php');
?>
INSERT, SELECT, UPDATE, DELETE, DROP etc ..operations
on the datbase.
Video Tutorial: Connecting To MySQL server From PHP
There are many variations of include:
include();
include_once();
require();
require_once();
require produces fatal error if the required file is not found. include produces warning when the file is not found.
include_once and require_once makes sure the files are included only once and not included multiple times in the same file.