Skip to content

setColumns

Ayoob edited this page Apr 11, 2020 · 2 revisions

setColumns

[easySQLite3 >= v0.1.0 (Beta)]

Set columns structure to create a table.

Description

setColumns( string $column_name , string $column_type [, boolean $isPrimary = false [, boolean $isUnique = false [, boolean $isAutoincrement = false ]]] ) : array

This function is used to build the columns structure to create a new table.

An array of columns data will be saved in the class to be used automatically when creating a new table, or the return value of this function can be passed to the createTable() function to create the table.

Note: it's highly recommended to call the function clearColumns() before starting to create the new structure.

Parameters

Parameter Description
column_name Name of the column that need to be created.
column_type The column type can be INTEGER, TEXT, REAL, NUMERIC, or BLOB. You can use those keywords or any keyword of the next table.
isPrimary Set this to true to make this column a Primary key.
isUnique Set this to true to make this column Unique.
isAutoincrement Set this to true to Autoincrement this column. This option will be ignored unless the column type is INTEGER and $isPrimary is set to true

Types

Type Keywords
INTEGER Any string that contains int or unsigned.
TEXT Any string that contains char, text, txt, var, or clob.
REAL Any string that contains real, doub, or floa.
NUMERIC Any string that contains num, deci, bool, date, or time.
BLOB Any string that contains blob or bin.

Return Values

The function returns an array containing the columns structure.

If column_name is not specified, or column_type is incorrect, the function will return false

Examples

Example #1 : Set columns structure

include "easySQLite3.class.php";

$db = new easySQLite3("database.sqlite");

$db->setTable( "MyTable" );

$db->clearColumns();

$db->setColumns("id", "int", true, false, true); // Column name is 'id',        type is 'INTEGER', will be primary column, and will be is_autoincremented.
$db->setColumns("mail", "text", false, true);    // Column name is 'mail',      type is 'TEXT',    will be unique column.
$db->setColumns("url", "char");                  // Column name is 'url',       type is 'TEXT'.
$db->setColumns("datestamp", "date");            // Column name is 'datestamp', type is 'NUMERIC'.
$db->setColumns("stt", "bool");                  // Column name is 'stt',       type is 'NUMERIC'.

if ( $db->createTable() ) {
    echo "Table was created successfully.";
}

Notes

Related Functions

  • getColumns - Get columns structure that was created using setColumns() function.
  • clearColumns - Clears the temporary columns structure that was created using setColumns() function.
  • createTable - Creating a new table in a database.
  • setTable - Set the default Table name to work with.

Back to Functions list

Clone this wiki locally