views:

67

answers:

1

Hello,

I have this php code, the files are hosted on another server and db else where

$hostname_xxx = "xxxdb.db.234141.mysqldbhosted.com";
$database_xxx = "xx11xx";
$username_xxx = "xx11xx";
$password_xxx = "xx332211xx";
$shasown = mysql_pconnect($hostname_xxx, $username_xxx, $password_xxx) or trigger_error(mysql_error(),E_USER_ERROR); 


$your_ip = $_SERVER['REMOTE_ADDR'];


echo $your_ip;



$insertSQL1 = "INSERT INTO  table (users_ip) VALUES ('$your_ip)";
mysql_select_db($database_xxx, $xxx);
$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

The error I am getting is

Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server during query in /domains/4444.com/html/55.php on line 8

Fatal error: Lost connection to MySQL server during query in /domains/4444.com/html/55.php on line 8

Thanks Jean

+2  A: 

mysql_pconnect() creates a persistent connection to the database, whereas mysql_connect() does not. IF you are creating a persistent connection, you need only connect once throughout your session, so if you're creating a persistent connection more than once this may be the cause.

On shared servers it may be worth trying mysql_connect() over mysql_pconnect() and see if this corrects the issue at hand. Also, in your code you have:

$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

But should be:

$Result21 = mysql_query($insertSQL1, $shasown) or die(mysql_error());

because $xxx was never a connection variable but $shasown is.

Personally I like to use mysqli_connect() as I find it to be a little faster.

webfac
Nope, you can use mysql_pconnect as many times as you want within your session, it will just reuse the connection you've already opened. But I wouldn't advise using persistent connections, you might run out of connections pretty quickly if you have a lot of concurrent users...
wimvds
@wimvds I said "you need only connect once throughout your session" not "you CAN or MUST only connect once throughout your session"
webfac
Besides, what would be the point int calling a persistent connection over and over? You may just as well be using mysql_connect(); then.
webfac