title: PHP MySQL connection persistence
body: <p>I've read a ton about persistent database connections between PHP and MySQL (mysql_connect vs. mysql_pconnect). Same with PDO and MySQLi.  It's definitely just my lack of understanding on this one, but how can a database connection be persistent between webpages?  In this code:</p>
  
  <pre><code>$conn = mysql_pconnect( $server , $user, $pass );
  mysql_select_db( $dbname );
  </code></pre>
  
  <p>If two users load this page at the same time, with two different $dbname variables, will PHP only make one connection to the database or two?  I am fairly certain that</p>
  
  <pre><code>$conn = mysql_connect( $server , $user, $pass );
  </code></pre>
  
  <p>would make two connections.</p>
  
  <p>If pconnect reuses the connection opened by the first user, will the mysql_select_db call work for the second user?</p>
  
  <p>Ideally, what I am looking for is a way to have fewer database connections but still be able to set the default database in each PHP script.  I have clients who all use the same PHP scripts, but the data is stored in their own client database (hence, $dbname is always different, but the MySQL connection parameters are the same - same mysql ip address, user and password).</p>
  
  <p>Hope that makes sense.  We can use MySQL, MySQLi or PDO, just need to know how to accomplish this the best way without having the possibility for clients to accidently write data to someone else's database! Thanks in advance.</p>