1) $tableName = $argv[1]; else { $table = readline("Table (schools): "); if (strlen(trim($table))) $tableName = $table; } $array = readline("Array (): "); $arrayName = ""; if (strlen(trim($array))) $arrayName = $array; $checkIfSet = 'N'; if (strlen($arrayName)) { $check = readline("Check if array key exists (N): "); if ($check == 'Y') $checkIfSet = 'Y'; } echo("\n"); $query = "SHOW columns FROM $tableName"; $results = db_query($query); while ($row = db_fetch_assoc($results)) { $field = $row['Field']; $type = $row['Type']; $default = $row['Default']; if ($row['Extra'] == 'auto_increment') continue; $prefix = ""; if (strlen($arrayName) && $checkIfSet == 'Y') $prefix = "if (!array_key_exists('$field',$".$arrayName.")) "; if (strlen($arrayName)) $field = $prefix . '$' . $arrayName . "['" . $field . "']"; else $field = '$'.$field; switch ($type) { case 'int': case 'int unsigned': case 'smallint': case 'smallint unsigned': case 'bigint': case 'bigint unsigned': if ($default == 'NULL') $default = '0'; printf("%-50s = $default;\n",$field); break; case 'decimal(12,2)': if ($default == 'NULL') $default = '0.0'; if ($default == '') $default = '0.0'; printf("%-50s = $default;\n",$field); break; case 'enum': case 'varchar': case 'char': if ($default == 'NULL') $default = ''; printf("%-50s = '$default';\n",$field); break; default: if ($default == 'NULL') $default = ''; printf("%-50s = '$default';\n",$field); } } echo("\n"); ?>