Select Chapter ❯
MySQL Tutorial
MySQL Connection
You can connect to a MySQL database easily with PHP using mysql_connect() function it returns TRUE on success or FALSE on failure.
Syntax
mysql_connect(host,username,password);
Code Explanation
- host: it is an optional parameter it takes the value of hostname. If not specified, then default value is localhost:3036.
- username: it is an optional parameter the username that access the database. Generally the default value is "root".
- password: it is an optional parameter the password of the username that access the database.The default value is empty.
Example of to Connect To MySQL Database using PHP
<?php $host = 'localhost:3036'; $user = 'root'; $pass = ''; $conn = mysql_connect($host, $user, $pass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($conn); ?>
To Disconnect From MySQL Database
You can disconnect from MySQL database using PHP mysql_close() function.
mysql_close($conn);
❮ PrevNext ❯