src/MySQL/MySQLTable.php
public function createSQL()
	{
		try {

			$lines = array();

			$indices = array();

			$columns = $this->columns;

			$template = "CREATE TABLE %s (\n%s,\n%s\n) ENGINE=%s DEFAULT CHARSET=%s;";

			foreach ($this->columns as $column_name => $column)
			{

				//$column_name = $column["name"];//set the column name

				$data_type = $column["type"];//set the column data type

				$length = $column["length"];//set the lenght of the data type

				if ($column["primary"])	$indices[] = "PRIMARY KEY ({$column_name})"; //add primary key field

				if ($column["index"]) $indices[] = "KEY {$column_name} ({$column_name})"; //add index field

				switch ($data_type)
				{
					case "autonumber":

						$lines[] = "{$column_name} INT(11) NOT NULL AUTO_INCREMENT";

						break;

					case "text":

						if ($length !== null && $length <= 255)	$lines[] = "{$column_name} VARCHAR({$length}) DEFAULT NULL";

						else $lines[] = "{$column_name} text";

						break;

					case "integer":

						$lines[] = "{$column_name} INT(11) DEFAULT NULL";

						break;

					case "decimal":

						$lines[] = "{$column_name} FLOAT DEFAULT NULL";

						break;

					case "boolean":

						$lines[] = "{$column_name} TINYINT(4) DEFAULT NULL";

						break;

					case "datetime":

						$lines[] = "{$column_name} DATETIME DEFAULT NULL";

						break;

				}

			}

			$this->query_string = sprintf($template, $this->table, join(",\n", $lines), join(",\n", $indices), 'InnoDB', 'utf8');//$this->connection->character_set_name()
			
			return $this;

		} catch (MySQLException $e) {

			$e->errorShow();

		}
		
	}
public function createSQL()
	{
		try {

			$lines = array();

			$indices = array();

			$columns = $this->columns;

			$template = "CREATE TABLE %s (\n%s,\n%s\n) ENGINE=%s DEFAULT CHARSET=%s;";

			foreach ($this->columns as $column_name => $column)
			{

				//$column_name = $column["name"];//set the column name

				$data_type = $column["type"];//set the column data type

				$length = $column["length"];//set the lenght of the data type

				if ($column["primary"])	$indices[] = "PRIMARY KEY ({$column_name})"; //add primary key field

				if ($column["index"]) $indices[] = "KEY {$column_name} ({$column_name})"; //add index field

				switch ($data_type)
				{
					case "autonumber":

						$lines[] = "{$column_name} INT(11) NOT NULL AUTO_INCREMENT";

						break;

					case "text":

						if ($length !== null && $length <= 255)	$lines[] = "{$column_name} VARCHAR({$length}) DEFAULT NULL";

						else $lines[] = "{$column_name} text";

						break;

					case "integer":

						$lines[] = "{$column_name} INT(11) DEFAULT NULL";

						break;

					case "decimal":

						$lines[] = "{$column_name} FLOAT DEFAULT NULL";

						break;

					case "boolean":

						$lines[] = "{$column_name} TINYINT(4) DEFAULT NULL";

						break;

					case "datetime":

						$lines[] = "{$column_name} DATETIME DEFAULT NULL";

						break;

				}

			}

			$this->query_string = sprintf($template, $this->table, join(",\n", $lines), join(",\n", $indices), 'InnoDB', 'utf8');//$this->connection->character_set_name()
			
			return $this;

		} catch (MySQLException $e) {

			$e->errorShow();

		}
		
	}
public function createSQL ( ) { try { $ lines = array ( ) ; $ indices = array ( ) ; $ columns = $ this -> columns ; $ template = "CREATE TABLE %s (\n%s,\n%s\n) ENGINE=%s DEFAULT CHARSET=%s;" ; foreach ( $ this -> columns as $ column_name => $ column ) { //$column_name = $column["name"];//set the column name $ data_type = $ column [ "type" ] ; //set the column data type $ length = $ column [ "length" ] ; //set the lenght of the data type if ( $ column [ "primary" ] ) $ indices [ ] = "PRIMARY KEY ({$column_name})" ; //add primary key field if ( $ column [ "index" ] ) $ indices [ ] = "KEY {$column_name} ({$column_name})" ; //add index field switch ( $ data_type ) { case "autonumber" : $ lines [ ] = "{$column_name} INT(11) NOT NULL AUTO_INCREMENT" ; break ; case "text" : if ( $ length !== null && $ length <= 255 ) $ lines [ ] = "{$column_name} VARCHAR({$length}) DEFAULT NULL" ; else $ lines [ ] = "{$column_name} text" ; break ; case "integer" : $ lines [ ] = "{$column_name} INT(11) DEFAULT NULL" ; break ; case "decimal" : $ lines [ ] = "{$column_name} FLOAT DEFAULT NULL" ; break ; case "boolean" : $ lines [ ] = "{$column_name} TINYINT(4) DEFAULT NULL" ; break ; case "datetime" : $ lines [ ] = "{$column_name} DATETIME DEFAULT NULL" ; break ; } } $ this -> query_string = sprintf ( $ template , $ this -> table , join ( ",\n" , $ lines ) , join ( ",\n" , $ indices ) , 'InnoDB' , 'utf8' ) ; //$this->connection->character_set_name() return $ this ; } catch ( MySQLException $ e ) { $ e -> errorShow ( ) ; } }
This method generates query string for creating the database table.
@param null
@return $this
This method generates query string for creating the database table .