API Documentation for: 1.1.1
Show:

CreateQuery Class

Extends Query
Namespace: Canteen\Database

Create a new truncate query

$tables = $db->create('users')
    ->fields(
        "msgid mediumint(8) unsigned NOT NULL AUTO_INCREMENT",
        "parent mediumint(8) unsigned NOT NULL DEFAULT '0'",
        "subject varchar(255) NOT NULL DEFAULT ''",
    )
    ->primaryKey('msgid')
    ->fulltextKey('subject')
    ->result();

Constructor

CreateQuery

(
  • db
  • table
)

Parameters:

  • db Database

    Reference to the database

  • table String

    The name of the table to add

Methods

__toString

() String

Represent the query as a SQL statement

Returns:

String:

The query in SQL string form

charset

(
  • charset
)
CreateQuery

Define the character set to use on table

Parameters:

  • charset String

    The name of the charset

Returns:

CreateQuery:

Instance of this call for chaining

collate

(
  • collate
)
CreateQuery

Define the character set collate to use on table

Parameters:

  • collate String

    The name of the collate

Returns:

CreateQuery:

Instance of this call for chaining

engine

(
  • engine
)
CreateQuery

Set the engine type

Parameters:

  • engine String

    The name of the engine to use for talbe

Returns:

CreateQuery:

Instance of this call for chaining

escape

(
  • value
)
String | Array protected

Inherited from Query:

Convenience function for escapeString method on Database

Parameters:

  • value String | Array

    The value or collection of values

Returns:

String | Array:

The value or collection of values

field

(
  • fieldName
  • The
  • [isNull=true]
  • [default]
  • [autoIncrement=false]
)
CreateQuery

Add a single field by name and properties

Parameters:

  • fieldName String

    The name of the field to add

  • The String

    properties, including the type

  • [isNull=true] Boolean optional

    If the value can be null

  • [default] String optional

    The default value, if any

  • [autoIncrement=false] Boolean optional

    If we should auto increment this field

Returns:

CreateQuery:

Instance of this call for chaining

fields

(
  • fields
)
CreateQuery

Add a collection of fields

Parameters:

  • fields String multiple

    Add a n-number of string arguments

Returns:

CreateQuery:

Instance of this call for chaining

fulltextKey

(
  • fieldName
)
CreateQuery

Create a fulltext key on the table

Parameters:

  • fieldName String

    The name of the field

Returns:

CreateQuery:

Instance of this call for chaining

internalKey

(
  • fieldName
  • [type='']
)
CreateQuery private

Internal method to create a key on the query

Parameters:

  • fieldName String

    The name of the field

  • [type=''] String optional

    Either UNIQUE, FULLTEXT or empty

Returns:

CreateQuery:

Instance of this call for chaining

key

(
  • fieldName
)
CreateQuery

Create a key on the table, this is non-unique and non-primary

Parameters:

  • fieldName String

    The name of the field

Returns:

CreateQuery:

Instance of this call for chaining

limit

(
  • lengthOrIndex
  • [duration=null]
)
Query

Inherited from Query:

The limit for query

Parameters:

  • lengthOrIndex Int

    Either the single limit number or index, duration

  • [duration=null] Int optional

    How many rows to fetch

Returns:

Query:

The instance of this query

orderBy

(
  • field
  • [order='asc']
)
Query

Inherited from Query:

How to order the results by

Parameters:

  • field String

    The property field

  • [order='asc'] String optional

    The order, either ASC or DESC

Returns:

Query:

The instance of this query

prepare

(
  • value
)
String protected

Inherited from Query:

Take an existing value we're about to input and escape it, if needed

Parameters:

  • value String

    A statement or sql property to evaluate

Returns:

String:

A string of an escaped, prepared SQL property

prepareField

(
  • field
)
String protected

Inherited from Query:

Take an existing field name we're about to input and

Parameters:

  • field String

    The name of a field

Returns:

String:

A string of an escaped, prepared SQL field name

primaryKey

(
  • fieldName
  • [startingValue=1]
)
CreateQuery

Create a primary key on the table, this is unique and primary

Parameters:

  • fieldName String

    The name of the field

  • [startingValue=1] Int optional

    The starting auto increment value

Returns:

CreateQuery:

Instance of this call for chaining

result

() Boolean

Inherited from Query:

Execute the query

Returns:

Boolean:

If result was successful

set

(
  • fieldName
  • value
  • [isNull=true]
  • [default]
)
CreateQuery

Add a character set field to the table

Parameters:

  • fieldName String
  • value Array

    The collection of string values

  • [isNull=true] Boolean optional

    If the value can be null

  • [default] String optional

    The default value, if any

Returns:

CreateQuery:

Instance of this call for chaining

setTables

(
  • tables
)
Query protected

Inherited from Query:

Create and insert query

Parameters:

  • tables Array | String multiple

    The table to insert into

Returns:

Query:

The instance of this query

uniqueKey

(
  • fieldName
)
CreateQuery

Create a unique key on the table, this is unique and non-primary

Parameters:

  • fieldName String

    The name of the field

Returns:

CreateQuery:

Instance of this call for chaining

where

(
  • args
)
Query

Inherited from Query:

Do a where selection

Parameters:

  • args Array | String multiple

    A single where statement or array of and statements, or list of arguments

Returns:

Query:

The instance of this query

Properties

charset

String private

The MySQL character set to use

Default: 'latin1'

collate

String private

The MySQL collate set to use

Default: 'latin1_general_ci'

db

Database protected

Inherited from Query:

The reference to the database connection, required!

engine

String private

The MySQL table engine to use

Default: 'MyISAM'

Int

The starting auto increment amount

Default: null

fields

Array private

The collection of fields to add

keys

Array private

The collection of keys to add

limit

String protected

Inherited from Query:

The limit

orderBy

String protected

Inherited from Query:

The order by

table

String private

The name of the table to create

tables

String protected

Inherited from Query:

The table or tables to insert into

where

String protected

Inherited from Query:

The array collection of where properties