...

View Full Version : Stop mysql connection



jdimino
02-19-2006, 08:42 PM
Hi
I cant seem to get this code to work for me, I want to stop mysql connection if a name exist on my database, can someone tell me what I'm doing wrong)



$connection = mysql_connect(localhost,xxxx_xx,xxxx) or die ("Couldn't connect to server.");
$db = mysql_select_db(xxxx_xxx, $connection) or die ("Couldn't select database.");
$sql = "SELECT Bloom_Name FROM ihsreg WHERE Bloom_Name = '$BloomName'";
$result = mysql_query($sql) or die("Couldn't execute query. ". mysql_error());$num = mysql_numrows($result);
if ($num > 0)
{
$name_exist = "$BloomName already Registered. Select another Name.";
echo $name_exist;
mysql_close($connection);
}
else
$name_ok = "$BloomName is not a Registered. You may use this Name.";
echo $name_ok;
$query="insert into ihsreg

StupidRalph
02-20-2006, 04:46 AM
What exactly are you trying to do? Are you sure you want to close the connection to the DB? If you close the connection that means the user can not interact with the database anymore until you open it back up. I can't remember right now but I think that the connection to the DB closes at the end of the script automatically anyway.

Is there a specific reason as to why you need to explicitly close the connection within your IF statement?

funhunter
02-20-2006, 09:44 AM
I put all activities concerning with database into different small functions, I connect and select DB inside them, so if my function exits, connection variable will be destroyed,isn't it?Do I have to explicitly close the connection like above code ?

raf
02-20-2006, 10:08 AM
please don't hijack this thread.
start a new one if you have a question of your own.

I put all activities concerning with database into different small functions, I connect and select DB inside them, so if my function exits, connection variable will be destroyed,isn't it?
i don't realy understand your question. but if you use the mysql_connect() inside a function, then there will still be only one connection opened in your script (unless you set the new-connection parameter in your mysql_connect() but i've never seen anyone do that)

Do I have to explicitly close the connection like above code ?
No. The connection will automatically be closed at the end of your script.

marek_mar
02-20-2006, 04:03 PM
mysql_close() (http://www.php.net/manual/en/function.mysql-close.php) ?

StupidRalph
02-20-2006, 08:45 PM
Yes. The connection is closed automagically at the end of the script unless you use mysql_pconnect() which means that it is a persistent connection that you should close using mysql_close.

raf
02-20-2006, 09:13 PM
Yes. The connection is closed automagically at the end of the script unless you use mysql_pconnect() which means that it is a persistent connection that you should close using mysql_close.
that's not correct.
mysql_close() does not close persistent connections

StupidRalph
02-20-2006, 09:23 PM
that's not correct.
mysql_close() does not close persistent connections

What am I thinking :confused: ..its persitent it doesn't close.

persistent -(adj.) Never-ceasing 2. Continually recurring to the mind. 3. Retained; not shed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum