Select MySQL DB

<?php
	/* Your mysql server host name */
	$host = "localhost";
	
	/* Mysql database user name */
	$user = "root";
	
	/* Mysql database user password */
	$pass = "yourpass";
	
	/* Open connection mysql server in mysqli procedural */
	$conn = mysqli_connect($host,$user,$pass);
	
	if($conn) {
		/* Select database */
		$result = mysqli_select_db($conn, "test");
		if($result)
			echo "Database selected and ready for query!";
		else
			echo "Error to select database!";
	}
	else
		echo "Connection to the Server could not be established!";
	
	/* Close mysqli connect */
	mysqli_close($conn);
		
	
	/* Open connection mysql server in mysqli object oriented */
	$conn = new mysqli($host,$user,$pass) or die("Connection to the Server could not be established!");
	
	if($conn) {
		
		/* Select database */
		$result = $conn->select_db("test");
		if($result)
			echo "Database selected and ready for query!";
		else
			echo "Error to select database!";
	}
	
	/* Close mysqli connect */
	$conn->close();
?>



/* Output */
Database selected and ready for query!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!