Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // file config.php
- $server = array(
- array('host'=>'host1', 'user'=>'username1', 'passw'=>'password1', 'db'=>'db_name1'),
- array('host'=>'host2', 'user'=>'username2', 'passw'=>'password2', 'db'=>'db_name2'),
- array('host'=>'host3', 'user'=>'username3', 'passw'=>'password3', 'db'=>'db_name3')
- );
- ?>
- <?php
- // file task.php
- /* bikin dulu table serverlog di semua server, buat log kalo elor
- CREATE TABLE IF NOT EXISTS `serverlog` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `tanggal` datetime NOT NULL,
- `keterangan` varchar(64) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- */
- include("config.php");
- for($i=0;$i<=$count($server);$i++){
- $conn = mysqli_connect($server[$i]['host'], $server[$i]['user'], $server[$i]['passw'], $server[$i]['db']) or die("Error " . mysqli_error($conn));
- $result = mysqli_query($conn,"select * from `table`");
- if($result) {
- $array = mysqli_fetch_array($result);
- $task = $array["field"];
- mysqli_free_result($result);
- mysqli_query($conn,"insert into `table2` set `field2`='".$task."'");
- } else {
- $error = "Error: " . mysqli_error($conn);
- $query = "insert into `serverlog` values (null, NOW(), '$error')";
- mysqli_query($conn,$query);
- }
- mysqli_close($conn);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment