下面的脚本用于更新 100 个数据库的模式。
我正在调用 mysql_connect,mysql_select_db 是否会导致建立另一个连接,或者我可以吗?(我运行这个脚本来更新 100 个左右数据库的架构)
$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";
}