Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <a href="http://php.net/mysql_pconnect/" rel="nofollow noreferrer"><code>mysql_pconnect</code></a>, that will do what you want.</p> <blockquote> <p>First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.</p> </blockquote> <p>You could also use a static or singleton class to handle connection pooling for you.</p> <pre><code>&lt;?php class dbConnectionPooler { static var $connections = array(); private static function createConnection($host, $username, $password, $db) { $connection = mysql_pconnect($host, $username, $password); if (FALSE !== $connection) { $result = mysql_select_db($db, $connection); if (FALSE !== $result) { self::$connections[self::getConnectionHash($host, $username, $password, $db)] = $connection; return $connection; } } } private static function getConnectionHash($host, $username, $password, $db) { return md5($host. $username. $password. $db); // use your favourite hashing function here } public static function getConnection($host, $username, $password, $db) { $connectionHash = self::getConnectionHash($host, $username, $password, $db); if (array_key_exists($connectionHash, self::$connections)) { return self::$connections[$connectionHash]; } else { return self::createConnection($host, $username, $password, $db); } return false; } } $connection = dbConnectionPooler::getConnection("dbhost", "dbuser", "dbpassword", "mydb"); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload