Share on Google+Share on Google+

PHP SQL close connection

PHP SQL close connection is used to close a connection between the PHP and SQL.

PHP SQL close connection


PHP SQL close connection is used to close a connection between the PHP and SQL.

Understand with Example

The Tutorial illustrate an example from 'PHP SQL close Connection'. To understand and grasp the example we include a server side scripting code that include the usename, password, host and database to connect with the database in the backend. Once the connection is built successfully between the PHP and SQL. You can retrieve the records from SQL and send it to browser as output. The connection is closed automatically  when the scripts end. To close connection we use mysql_close ( ) function. 





$host = "localhost";
$user = "root";
$password = "root";
$database = "komal";
$connection = mysql_connect($host,$user,$password) 
	or die("Could not connect: ".mysql_error());
	or die("Error in selecting the database:".mysql_error());
$sql="Select * from stu";
	or exit("Sql Error".mysql_error());
echo "<table width =\"20%\" bgcolor=\"#F5F5FF\">";
echo "<tr>";
echo "<td ><b>Id</b></td> <td><b>Name</b></td>";
echo "</tr>";
	echo "<tr><td>".$id."</td>";
	echo "<td>".$name."</td>";
}	s
echo "</table>";
echo "<br><b>Connection closed</b>";



Id Name

Connection closed


Posted on: January 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: PHP SQL close connection  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image