6363 $ sql = "INSERT INTO $ tableArchive SELECT * FROM $ table WHERE $ pk >= $ min AND $ pk < $ max " ;
6464 file_put_contents (
6565 $ logFile ,
66- "Moving rows $ min to " .($ max- 1 )." to $ tableArchive. Starting at " .date ('Y-m-d H:i:s ' )."\n" ,
66+ "Moving rows $ min to " .($ max - 1 )." to $ tableArchive. Starting at " .date ('Y-m-d H:i:s ' )."\n" ,
6767 FILE_APPEND
6868 );
6969 $ res = Database::query ($ sql );
112112);
113113
114114/**
115- * Returns the name of the primary key column for the given table
115+ * Returns the name of the primary key column for the given table.
116116 *
117117 * @param string $table The name of the table
118118 *
119119 * @return string The column name of the primary key
120120 */
121- function getPKFromTable ($ table ) {
121+ function getPKFromTable ($ table )
122+ {
122123 $ sql = "SELECT k.column_name
123124 FROM information_schema.table_constraints t
124125 JOIN information_schema.key_column_usage k
@@ -129,20 +130,23 @@ function getPKFromTable($table) {
129130 $ res = Database::query ($ sql );
130131 if (Database::num_rows ($ res ) > 0 ) {
131132 $ row = Database::fetch_assoc ($ res );
133+
132134 return $ row ['column_name ' ];
133135 }
136+
134137 return '' ;
135138}
136139
137140/**
138- * Check a table exists and create it if it doesn't
141+ * Check a table exists and create it if it doesn't.
139142 *
140- * @param string $table The table to check/create
143+ * @param string $table The table to check/create
141144 * @param string $templateTable The model from which this table should be created
142145 *
143146 * @return bool True if it exists *or* it could be created, false if there was an error at create time
144147 */
145- function checkAndCreateTable ($ table , $ templateTable ) {
148+ function checkAndCreateTable ($ table , $ templateTable )
149+ {
146150 $ sqlCheck = "SHOW TABLES LIKE ' $ table' " ;
147151 $ res = Database::query ($ sqlCheck );
148152 if (Database::num_rows ($ res ) > 0 ) {
@@ -151,6 +155,7 @@ function checkAndCreateTable($table, $templateTable) {
151155 } else {
152156 $ sqlCreate = "CREATE TABLE $ table like $ templateTable " ;
153157 $ res = Database::query ($ sqlCreate );
158+
154159 return $ res ;
155160 }
156161}
0 commit comments