Exemplo n.º 1
0
 public static function describeTable($tname)
 {
     Makiavelo::info("Doing a describe table for '" . DBLayer::getDBName() . " - {$tname}'");
     $db = DBLayer::connect();
     $res = mysql_query("show columns from {$tname}", $db);
     $return = array();
     if (!$res) {
         Makiavelo::info("Error:: " . mysql_error());
     } else {
         while ($data = mysql_fetch_assoc($res)) {
             //Makiavelo::info("Field data: " . print_r($data, true));
             $return[$data['Field']] = $data['Type'];
         }
     }
     //DBLayer::disconnect($db);
     //Makiavelo::info("table description: " . print_r($return, true));
     return $return;
 }
Exemplo n.º 2
0
 public function execute($params)
 {
     Makiavelo::info("Creating Database...");
     $sql_folder_path = ROOT_PATH . Makiavelo::SQL_CREATE_TABLES_FOLDER;
     Makiavelo::puts("Creating database...");
     $conn = DBLayer::connect();
     $db_name = DBLayer::getDBName();
     $sql = "CREATE DATABASE `{$db_name}`";
     if (!mysql_query($sql, $conn)) {
         Makiavelo::info("ERROR creating db: " . mysql_error());
     }
     //We also have to create the migrations table
     $sql_migrations = "CREATE TABLE migrations ( migration INT PRIMARY KEY);";
     mysql_select_db($db_name);
     if (!mysql_query($sql_migrations, $conn)) {
         Makiavelo::info("ERROR creating migrations table:: " . mysql_error());
     }
     DBLayer::disconnect($conn);
 }