如果你有N个站,所有的网站都要进行一系列的后台操作,那么如果一个个去登陆然后操作是繁琐而且浪费时间的。下面的这个脚本是用来开关支付方式并设定顺序,当然里面没有涉及到设置商户和返回链接这几个动作。需要进一步完善。
<?php
/*
@author george zheng <xinhaozheng@gmail.com>
@date 2012.03.12
@usage php scriptname 'key of info to use'
*/
$info = array(
'f1' => array('root','xxxxx'),
'f2' => array('root','xxxxx'),
'f3' => array('root','xxxxx'),
'f4' => array('root','xxxxx'),
'f5' => array('root','Xxxxx'),
);
if ($argc < 2) {
die('Pls secify the mysql profile to use'."\n");
} else {
$dbuser = $info[$argv[1]][0];
$dbpass = $info[$argv[1]][1];
}
set_time_limit(0);
$link = @mysql_connect('localhost', $dbuser, $dbpass)
or die("Database connnected error \n");
try{
$db_list = @mysql_list_dbs($link) or die("Can not get database list \n");
} catch(Exception $ex) {
echo "Database connnected error \n";
exit;
}
$count = 0;
while ($row = mysql_fetch_object($db_list)) {
$db = $row->Database;
if(table_exists($link, $db, 'configuration')){
//echo $db."\n";continue;
$count++;
mysql_select_db($db, $link);
//mysql_select_db('uggsnorg_onorge', $link);
$sql = "update configuration set configuration_value='2' where configuration_key='MODULE_PAYMENT_PAYEASE_SORT_ORDER'";
sql_query($sql, $link);
$sql = "update configuration set configuration_value='1' where configuration_key='MODULE_PAYMENT_IPS_SORT_ORDER'";
sql_query($sql, $link);
$sql = "update configuration set configuration_value='True' where configuration_key='MODULE_PAYMENT_IPS_STATUS' OR configuration_key='MODULE_PAYMENT_PAYEASE_STATUS'";
sql_query($sql, $link);
$sql = "update configuration set configuration_value=0 WHERE configuration_key='MODULE_PAYMENT_PAYEASE_ZONE'";
sql_query($sql, $link);
$result = mysql_query("select configuration_value from `configuration` where configuration_key = 'MODULE_PAYMENT_INSTALLED';");
$payment_keys = '';
while($row = mysql_fetch_array($result)){
$payment_keys = $row['configuration_value'];
}
$payment_arr = explode(";",$payment_keys);
$install_payment = "";
$pay_arr = array();
foreach($payment_arr as $k=>$val){
if ($val=='payease.php') {
$pay_arr[1]='payease.php';
} elseif ($val=='ips.php') {
$pay_arr[0]='ips.php';
}
}
ksort($pay_arr);
$install_payment = implode(";",$pay_arr);
sql_query("update `configuration` set configuration_value='$install_payment' where configuration_key='MODULE_PAYMENT_INSTALLED'",$link);
echo "\n" . $db .' updated successfully' . "\n";
} else {
echo $db.' has no configuration table' . "\n";
}
}
mysql_close($link);
echo 'Total ' . $count . ' databases updated successfully!';
function sql_query($query, $link)
{
if (empty($query)) {
die('Sql can not be empty' . "\n");
}
$result = mysql_query($query, $link);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
echo 'query successfully!' . "\n" . $query . "\n";
}
}
function table_exists($link,$db,$table) {
if (empty($table)) {
die('No table name provided to check');
}
$tables = array();
$sql = "SHOW TABLES FROM $db";
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}
return in_array('configuration', $tables);
// return FALSE;
// return TRUE;
}
?>