public function update() { $connection = EasyConnect::getInstance(); //so here we get the primary key name foreach ($this->primary_keys as $pkey_name) { if (!isset($this->{$pkey_name})) { throw new Exception("Cannot update a row w/o primary key"); } } $update_sets = ''; foreach ($this->columns as $column => $properties) { if (isset($this->{$column}) && !@$properties['auto_increment'] && !@$properties['primary_key']) { $update_sets .= "`" . $column . "`= '" . mysqli_real_escape_string($connection::get_conn(), $this->{$column}) . "',"; } } if (empty($update_sets)) { //no need to update return true; } $update_sets = substr($update_sets, 0, -1); $where_clause = ""; foreach ($this->primary_keys as $key => $pkey) { if ($key > 0) { $where_clause .= " AND "; } $where_clause .= "`" . $pkey . "` = '" . $this->{$pkey} . "'"; } $sql = "Update `" . $this->table_name . "` SET " . $update_sets . " WHERE " . $where_clause; $connection = EasyConnect::getInstance(); $connection->query($sql); return true; }
$base_model_directory = $model_directory . "Base/"; $options = getopt("", array("table:", "host:", "user:"******"pass:"******"database:")); $table = $options['table']; if ($options["host"]) { $host = $options["host"]; } if ($options["user"]) { $user = $options["user"]; } if ($options["pass"]) { $pass = $options["pass"]; } if ($options["database"]) { $database = $options["database"]; } $db = EasyConnect::getInstance($host, $user, $pass, $database); $query = "Describe `{$table}`"; $results = $db->fetchAssoc($query); $table_new_name = str_replace("_", " ", $table); $table_new_name = Ucwords($table_new_name); $table_new_name = str_replace(" ", "", $table_new_name); $file_content = '<?php namespace TModel\\Base; use TaysORM\\TaysORMBase; class ' . $table_new_name . 'Base extends TaysORMBase { public $table_name="' . $table . '"; public $primary_keys = ' . get_primary_key($results) . '; public $columns=array(