user_id SMALLINT UNSIGNED NOT NULL, PRIMARY KEY(post_id, user_id), FOREIGN KEY(post_id) REFERENCES Posts(post_id), FOREIGN KEY(user_id) REFERENCES Users(user_id) ); '); return $creator[$n_statement]; } #####################Calls methods######################## #Create Mysql object $installer = new MysqlConnector(); #Connect to mysql $installer->connectMysql(); #Uninstall old tables for ($i = 0; $i < 5; $i++) { if ($installer->connection->query(deleteTables($i)) === TRUE) { echo "Deleted <br>"; } else { echo $installer->connection->error . '<br>'; } } #Install new tables for ($i = 0; $i < 5; $i++) { if ($installer->connection->query(addTables($i)) === TRUE) { echo "Created <br>"; } else { echo $installer->connection->error . '<br>'; } } #Disconnect from Mysql $installer->disconnectMysql();
/** * convertDB() * Converts the DB, check's if it should be done first (ie: adding fields/tables) * @return bool */ function convertDB() { $settingsFile = dirname(realpath(__FILE__)) . "/settings.php"; include $settingsFile; // Reimport :) echo ":: Connecting to DB Server...."; $errorMsg = null; $conn = connectDB($databaseType, MYSERVER, MYLOGIN, MYPASSWORD, MYDATABASE); if (!empty($conn)) { echo "<font style='font-weight: bold;color: green'>done</font> :: <br />"; } else { echo "<font style='font-weight: bold;color: red'>ERROR</font> :: <br />"; return false; } echo ":: Beggining Database Conversion... :: <br /><ul>"; //Add Tables echo "<li>Adding new tables..."; //Add the DB Vars and let's try to do this stuffs.. if (addTables($databaseType, $conn, $tablePrefix, $errorMsg)) { echo "<font style='color: green;font-weight: bold'>completed</font>"; } else { echo "<font style='color: red;font-weight: bold'>error</font>"; if (!empty($errorMsg)) { echo "<br /><b>Error Messages: </b>{$errorMsg}"; } return false; } //Now let's reset the Error message, just in case $errorMsg = null; //Modify existing tables echo "<li>Updating existing tables..."; if (modTables($databaseType, $conn, $tablePrefix, $errorMsg)) { echo "<font style='color: green;font-weight: bold'>completed</font>"; } else { echo "<font style='color: red;font-weight: bold'>error</font>"; if (!empty($errorMsg)) { echo "<br /><b>Error Messages: </b>{$errorMsg}"; } return false; } //Run tests $errorMsg = null; // echo "<li>Verifying everything went okay..."; echo "</ul>:: Ending Conversion ::"; return true; }
<?php require_once "Common.php"; /* * Global Variables */ $drop_database = true; $mysqli = null; $tables = array('company', 'division', 'person', 'project', 'projectpartner', 'mgmt', 'proj_rev'); // "MAIN" function connectToDatabase(DATABASE_HOST, DATABASE_USER, DATABASE_USER_PASSWORD, DATABASE_NAME); dropExistingTables(); /* Drop allof the existing tables */ addTables(); /* Add the tables back */ $data_array = simplexml_load_file('company.xml'); $count = 1; /* * Loop through each company */ foreach ($data_array as $company) { $company_id = addCompany($company['name']); foreach ($company->CONTACT as $contact) { $query = "INSERT INTO person (person_firstname, person_lastname, person_company, person_email) " . "VALUES ('" . $contact['firstname'] . "', '" . $contact['lastname'] . "', {$company_id}, '" . $contact['email'] . "')"; $result = $mysqli->query($query); } foreach ($company->DIVISION as $division) { /* Check to see if this division name has already been added */ $query = "SELECT division_id, division_title FROM division where division_title = '" . $division['name'] . "'"; $result = $mysqli->query($query); if ($mysqli->affected_rows == 0) {