PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Diogo Resende   DBSync   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Test script
Class: DBSync
Synchronize the schema of MySQL databases
Author: By
Last change:
Date: 18 years ago
Size: 6,973 bytes
 

Contents

Class file image Download
<?php
    $error
= '';
   
$ok = false;

    if (isset(
$_POST['submit'])) {
       
$fields = array(
           
'type' => 'Database Type',
           
'host' => 'Database Host',
           
'user' => 'Database Username',
           
'pass' => 'Database Password',
           
'db' => 'Database Name'
       
);
        foreach (
$fields as $field => $name) {
           
$_POST['h'.$field] = trim(stripslashes($_POST['h'.$field]));
            if (
strlen($_POST['h'.$field]) == 0) {
               
$error = 'Local ' . $name . ' required';
                break;
            }
           
$_POST['s'.$field] = trim(stripslashes($_POST['s'.$field]));
            if (
strlen($_POST['s'.$field]) == 0) {
               
$error = 'Remote ' . $name . ' required';
                break;
            }
        }

        if (
strlen($error) == 0) {
            include
'class.dbsync.php';

           
$dbsync = new DBSync();

           
$dbsync->SetHomeDatabase($_POST['hdb'], $_POST['htype'], $_POST['hhost'], $_POST['huser'], $_POST['hpass']);
           
$dbsync->AddSyncDatabase($_POST['sdb'], $_POST['stype'], $_POST['shost'], $_POST['suser'], $_POST['spass']);

           
$ok = true;
            if (!
$dbsync->Sync()) {
               
$error = 'Something went wrong with synchronising...';
            }
        }
    }
?>
<html>
    <head>
        <title>Sync Remote Database width Local Database</title>
        <style type="text/css">
        <!--
            body,td,input,select {
                font-family: "Lusida Sans Unicode", Arial, Tahoma, Verdana, sans-serif;
                font-size: 9pt;
            }
            body {
                background-color: #fff;
                color: #000;
            }
            h3 {
                font-size: 12pt;
                font-weight: bold;
                margin: 0;
            }
            hr {
                height: 1px;
                border: 0;
                color: #ccc;
                background-color: #ccc;
            }
            .error {
                color: #a00;
            }
        //-->
        </style>
    </head>
    <body>
        <h3>Sync Remote Database width Local Database</h3><hr />
<?php
   
if ($ok) {
        if (
strlen($error) == 0) {
?>
Database <strong><?php echo $_POST['sdb']; ?></strong> at <strong><?php echo "{$_POST['suser']}@{$_POST['shost']}"; ?></strong> is now synchronised!<br />
        <br />
        <input type="button" value="<< More" onClick="javascript:history.back(1);" />
        <input type="button" value="Quit" onClick="javascript:window.close();" />
<?php
       
} else {
?>
<span class="error"><strong>Sync failed:</strong> <?php echo $error; ?></span><br />
        <br />
        <input type="button" value="<< Try Again" onClick="javascript:history.back(1);" />
        <input type="button" value="Quit" onClick="javascript:window.close();" />
<?php
       
}
    } else {
?>
<table border="0" width="500">
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
       
if (strlen($error) > 0) {
?>
<tr>
                <td colspan="3" align="center"><span class="error"><strong>Error</strong>: <?php echo $error; ?></span></td>
            </tr>
<?php
       
}
?>
<tr>
                <td width="45%">
                    <table border="0" cellpadding="3" width="100%">
                        <tr>
                            <td colspan="2" align="center"><strong>Local Database</strong></td>
                        </tr>
                        <tr>
                            <td width="50%" align="right"><label for="htype">Host</label></td>
                            <td width="50%">
                                <select id="htype" name="htype" style="width:100px">
                                    <option value="mysql">MySQL</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><label for="hhost">Host</label></td>
                            <td><input type="text" id="hhost" name="hhost" value="localhost" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="huser">Username</label></td>
                            <td><input type="text" id="huser" name="huser" value="root" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="hpass">Password</label></td>
                            <td><input type="password" id="hpass" name="hpass" value="" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="hdb">Database</label></td>
                            <td><input type="text" id="hdb" name="hdb" value="" style="width:100px" /></td>
                        </tr>
                    </table>
                </td>
                <td width="10%" align="right"><img src="reload.png" /></td>
                <td width="45%">
                    <table border="0" cellpadding="3" width="100%">
                        <tr>
                            <td colspan="2" align="center"><strong>Remote Database</strong></td>
                        </tr>
                        <tr>
                            <td width="50%" align="right"><label for="stype">Host</label></td>
                            <td width="50%">
                                <select id="stype" name="stype" style="width:100px">
                                    <option value="mysql">MySQL</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><label for="shost">Host</label></td>
                            <td><input type="text" id="shost" name="shost" value="" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="suser">Username</label></td>
                            <td><input type="text" id="suser" name="suser" value="" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="spass">Password</label></td>
                            <td><input type="password" id="spass" name="spass" value="" style="width:100px" /></td>
                        </tr>
                        <tr>
                            <td align="right"><label for="sdb">Database</label></td>
                            <td><input type="text" id="sdb" name="sdb" value="" style="width:100px" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3" align="right"><input type="submit" name="submit" value="Synchronise >>" /></td>
            </tr>
            </form>
        </table>
<?php
   
}
?>
</body>
</html>