First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
include "db.php";
|
||||
|
||||
$tableName = "schools";
|
||||
if ($argc > 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");
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user