Mysql Connection

PHP Programming

PHP Programming Examples

<?php
	/* Your mysql server host name */
	$host = "localhost";
	
	/* Mysql database user name */
	$user = "root";
	
	/* Mysql database user password */
	$password = "yourpassword";
	
	/* Mysql database name */
	$database = "test";
	
	
	/* Open connection mysql server in mysqli procedural */
	$connect = mysqli_connect($host, $user, $password, $database);
	
	if($connect)
		echo "Connection Establish with database!";
	else
		die("Connection to the Server could not be established!");
	

	/* Open connection mysql server in mysqli object oriented */
	$connect = new mysqli($host,$user, $password, $database) or die("Connection to the Server could not be established!");
	if($connect)
		echo "<br />Connection Establish with database!"; 
?> 



          /****** Output ******/
          

Connection Establish with database!


Connection Establish with database!

Learn more about mysql_connect and mysqli::__construct()