Preventing too many database connections

I have an include file for my database connections that has the following code:

$my_db_link = mysql_connect('my_host', 'my_username', 'my_password');
if (!$my_db_link) {
    die('Could not connect: ' . mysql_error());
}

$my_db_name = 'my_database';
mysql_select_db($my_db_name);

Will it make a difference if I use include_once () rather than include () or require_once () rather than require ()? We had the recent error, “too many connections” (“PHP Warning: mysql_connect () [function.mysql-connect]: Too many connections”), and I wonder if using include () created more connections than necessary.

include_once('my_db_connect.php');

instead

include('my_db_connect.php');
+3
source share
4 answers

require() include(), , -. , include() , script . () , script .

require_once

require_once() require(), , PHP , , , () .

Apache MySQL, , , MySQL.

mysql_pconnect() .

+1

, include_once(), include() require_once(), require()?

. include_once/require_once . PHP stat() , * _once() , , . , ; PHP , - , " ".

edit: http://www.techyouruniverse.com/software/php-performance-tip-require-versus-require_once

-, .:)

+1

include_once include . , mysql_connect , .

mysql_pconnect :

mysql_pconnect() mysql_connect() .

-, () , , . , .

Secondly, the connection to the SQL server will not be closed when the script completes. Instead, the link will remain open for future use ( mysql_close()it will not close the links installed mysql_pconnect()).

0
source

All Articles