API Documentation for: 1.1.1
Show:

InsertQuery Class

Extends Query
Namespace: Canteen\Database

Insert query to add a row to a table

$inserted = $db->insert('user')->values(array(
    'first_name' => 'Jim',
    'last_name' => 'Smith
));

Constructor

InsertQuery

(
  • db
  • tables
)

Parameters:

  • db Database

    Reference to the database

  • tables Array | String multiple

    The tables to insert into

Methods

__toString

() String

Represent the query as a SQL statement

Returns:

String:

The query in SQL string form

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

fields

(
  • fields
)
InsertQuery

The fields to insert into

Parameters:

  • fields String | Array multiple

    The array of fields or n number of arguments

Returns:

InsertQuery:

The instance of this query

isAssoc

(
  • arr
)
Boolean private

Check to see if an array is associative

Parameters:

  • arr Array

    The array to check

Returns:

Boolean:

if the array is associative

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

result

() Int

Inherited from Query

Execute the query

Returns:

Int:

The id of the last insert

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

values

(
  • values
)
InsertQuery

Add values

Parameters:

  • values Dictionary

    The values to add. Add multiple row by setting the fields() then adding sequential array. Add a single row by passing an associative array of field names to values.

Returns:

InsertQuery:

The instance of this query

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

db

Database protected

Inherited from Query:

The reference to the database connection, required!

fields

String protected

The field names

limit

String protected

Inherited from Query:

The limit

orderBy

String protected

Inherited from Query:

The order by

tables

String protected

Inherited from Query:

The table or tables to insert into

values

Array protected

The collection of values

where

String protected

Inherited from Query:

The array collection of where properties