0

Hi,

I want to re-use already estanbished DB connection but I don't know know how to do it. Please help me to modify my code below.

Thanks in advance

function connectDB(){
	$host = "localhost";
	$uid = "root";
	$psw = "";
	$db = "mydb";

	
	$hostc = @mysql_connect($host, $uid, $psw);

	if($hostc){
		$dbc = mysql_select_db($db);
		if(! $dbc){
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

$result = connectDB();

if($result === true){
	echo "OK";
} else {
	echo "NO";
}
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by veledrom
0
<?php
$connection1 = mysql_connect("hostname","username","password",true);
$connection2 = mysql_connect("hostname","username","password",true);

$db_selected1 = mysql_select_db('db1', $connection1);
$db_selected2 = mysql_select_db('db1', $connection2);
?>

It will create a new connection without disturbing the old connection.
If you face any problem regarding this again inform me.
Good luck.

Edited by mahavir123: n/a

0

I don't want to establish another connection when I call function above. If I already called it then it should use previous one to avoid connecting to mysql second time.

Edited by veledrom: .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.