The script below is used for updating schema of 100 databases.
I am making one call to mysql_connect, does mysql_select_db cause another connection to be made or am I ok? (I run this script to update the schema of 100 or so database)
$conn = mysql_connect("localhost", "root", "PASSWORD");
$show_db_query = mysql_query('SHOW databases');
$databases = array();
while ($row = mysql_fetch_assoc($show_db_query))
{
if (!in_array($row['Database'], $exclude_dbs))
{
$databases[] = $row['Database'];
}
}
foreach($databases as $database)
{
mysql_select_db($database, $conn);
echo "Running queries on $database\n***********************************\n";
foreach($sql_queries as $query)
{
if (!empty($query))
{
echo "$query;";
if (!mysql_query($query))
{
echo "\n\nERROR: ".mysql_error()."\n\n";
}
}
}
echo "\n\n";
}
As long as
mysql_select_dbfound a last connection or a connection identifer is supplied with the calling statment, it does not create a new connection.Since you are passing a connection identifer so it does not create a new connection to mysql. you are safe to go in this case of multiple connection but be aware that
mysqlextension is no longer maintained, you could trymysqliorPDO.