if ($result) { $row = iDatabase::fetch_row($result); $old_count = $row[0]; } else { Log::error("Count(*) in table $old_table failed"); } Log::notice("# rows in $old_table: $old_count"); $sql = "SELECT * FROM $old_table"; $result = iDatabase::query($sql); $count = 0; /* Loads the main database */ iDatabase::select_db($dbNameForm); while($row = iDatabase::fetch_array($result, 'ASSOC')) { $row['c_id'] = $course_id; $id = iDatabase::insert($new_table, $row); if (is_numeric($id)) { $count++; } else { $errors[$old_table][] = $row; } } Log::notice("#rows inserted in $new_table: $count"); if ($old_count != $count) { Log::error("ERROR count of new and old table doesn't match: $old_count - $new_table"); Log::error("Check the results: ");
if (iDatabase::num_rows($res) > 0) { $i = 0; $list = array(); while ($row = iDatabase::fetch_array($res)) { $list[] = $row; $i++; } foreach ($list as $row_course) { // Now use the $c_q_list /** * We connect to the right DB first to make sure we can use the queries * without a database name */ if (!$singleDbForm) { //otherwise just use the main one iDatabase::select_db($row_course['db_name']); } Log::notice('Course db ' . $row_course['db_name']); foreach ($c_q_list as $query) { if ($singleDbForm) { $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query); } if ($only_test) { Log::notice("iDatabase::query(".$row_course['db_name'].",$query)"); } else { $res = iDatabase::query($query); if ($log) { Log::notice("In ".$row_course['db_name'].", executed: $query"); }
$i = 0; while ($row = iDatabase::fetch_array($res)) { $list[] = $row; $i++; } foreach ($list as $row) { // Now use the $c_q_list /** * We connect to the right DB first to make sure we can use the queries * without a database name */ $prefix_course = $prefix; if ($singleDbForm) { $prefix_course = $prefix . $row['db_name'] . "_"; } else { iDatabase::select_db($row['db_name']); } foreach ($c_q_list as $query) { if ($singleDbForm) { //otherwise just use the main one $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query); } if ($only_test) { Log::notice("Database::query(" . $row['db_name'] . ",$query)"); } else { $res = iDatabase::query($query); if ($log) { Log::notice("In " . $row['db_name'] . ", executed: $query"); } } }