abdul_zu Posted November 16, 2009 Share Posted November 16, 2009 HI, How i can know if my PHP web application already connected to MySQL or Not? From this i will avoid lot of connection in my whole PHP application. I tired the following but it gives error: function connect() { $result = mysql_pconnect($GLOBALS['dbserver'], $GLOBALS['dbuser'], $GLOBALS['dbpws']); if (!$result) return false; if (!mysql_select_db($GLOBALS['dbname'])) return false; return $result; } Then i try to ping but i got error. if (!mysql_ping()){connect();} Warning: mysql_ping(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/html/auth.php on line 10 Please point to call only connect() function if there is not connection to mySQL? Link to comment https://forums.phpfreaks.com/topic/181746-mysql-connection-status/ Share on other sites More sharing options...
wildteen88 Posted November 16, 2009 Share Posted November 16, 2009 You should only need to call your 'connect()' function once. You dont need to keep calling that function every time you perform a query. Link to comment https://forums.phpfreaks.com/topic/181746-mysql-connection-status/#findComment-958597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.