GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Does this PHP code look OK? (https://gfy.com/showthread.php?t=459524)

Steen2 04-24-2005 11:29 AM

Does this PHP code look OK?
 
PHP Code:

    function mysqlconn() {
         
$user "DB_DB";
         
$pass "pass";
         
$db "DB_DB";
         
$newconnect mysql_pconnect(localhost$user,$pass) or die(mysql_error());
         
mysql_select_db($db) or die(mysql_error());
         if(
mysql_error()) { echo mysql_error(); }
    } 

It's causing this error in my error logs and looks to be hurting the server: PHP Warning: mysql_pconnect(): Link to server lost, unable to reconnect in ...

The line the error references is
$user = "DB_DB";

But I included the lines around it for better insight.

ssp 04-24-2005 11:38 AM

Have you tried using all lower cases in your username?

Steen2 04-24-2005 11:42 AM

Quote:

Originally Posted by ssp
Have you tried using all lower cases in your username?

Sorry?

"DB_DB" is to edit out information that's "sensitive".

ssp 04-24-2005 11:44 AM

Perhaps it's because there is a space in this line:

mysql_pconnect(localhost, $user,$pass)

Calvinguy 04-24-2005 11:52 AM

Try to use single qoutes ' rather then doubleqoutes "


or put qoutes around localhost also...

Steen2 04-24-2005 12:14 PM

Quote:

Originally Posted by ssp
Perhaps it's because there is a space in this line:

mysql_pconnect(localhost, $user,$pass)

Quote:

Try to use single qoutes ' rather then doubleqoutes "


or put qoutes around localhost also...
Thanks, but would this crash the server's mysql?

Serge Litehead 04-24-2005 12:23 PM

put localhost in single qoutes
whitespace such as spaces, tabs, etc in code is ignored

seems there s a prob with connection rather than anything else at this point
i've never used mysql_pconnect, see if mysql_connect works better for you.

Nysus 04-24-2005 12:26 PM

Hope you're putting that function in an include file as opposed to on a page, or have multiple DBs at different locations to use... you only need to connect to a mySQL server once each load.

Matt

who 04-24-2005 12:28 PM

Is your username the same as the database name?

Serge Litehead 04-24-2005 12:28 PM

here is a good sample for you from php manual:

Code:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die (mysql_error());
db_selected = mysql_select_db('db_name', $link) or die (mysql_error());

or die() is not recommended for use in live production.

Serge Litehead 04-24-2005 12:34 PM

err in above post

db_selected = $db_selected


All times are GMT -7. The time now is 03:26 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123