Database Library (Part 1)



( ZN >= 1.0.0 )

ZN Framework has a database library built to support different database platforms. Which platforms are supported is explained in the previous section. In particular, this library has been developed by taking the MySQL platform as the center. Database classes, which are fully compatible with MySQL, have been extended to provide almost complete compatibility with other database platforms.

Thanks to the Database library, you can create queries without writing any SQL code. Especially the syntax is very meaningful and the users can understand the codes. With ZN Framework's Database library, we think you will write code with great pleasure and enjoyment. The ZN Framework, the basic principle of simplicity, has tried to show this principle in the library.

 

 

# Security of Data


The ZN Framework Database Library has taken some precautions to prevent SQL Injection attacks. Quotation marks are recorded by converting to HTML numeric code in data with a single quote (') . Double quotes are allowed, but security methods are included to reduce some risks. Even if no security measures are taken in your inquiries, data security is provided at a high level, but no one can give you a 100% guarantee on data security today, even with the most advanced security systems.

 

 

# Methods


this select ( String ... $ condition )
this where ( Mixed $ column , String $ value = NULL , String $ logical = NULL )
this whereColumnNameCondition ( Scalar $ data )
this whereGroup ( Array ... $ args )
this having ( Mixed $ column , String $ value = NULL , String $ logical = NULL )
this havingGroup ( Array ... $ args )
this groupBy ( String ... $ condition )
this orderBy ( Mixed $ condition , String $ type = NULL )
this limit ( Int $ start = NULL , Int $ limit = 0 )
this get ( String $ table , String $ return = 'object' )
this tableNameGet ( Void )
Object result ( String $ type = 'object' )
Array resultArray ( Void )
String resultJson ( Void )
Object tableNameResult ( Void )
Object row ( Scalar $ printable )
Object tableNameRow ( Void )
String value (String $column = NULL)
Int totalrows ( Boolean $ total = false )
Int totalColumns ( Void )
Array columns ( Void )
Object columnData ( String $ column )
String tableName ( Void )
String pagination ( String $ url = NULL , Array $ settings = [] , Bool $ output = true )
this status ( String $ table )
Bool isExists ( String $ table , String $ column , String $ value )
Bool insert ( String $ table = NULL , Array $ datas = [] )
this duplicateCheck ( String ... $ args )
this duplicateCheckUpdate ( String ... $ args )
Int insertID ( Void )
Int affectedRows ( Void )
Bool insertCSV ( String $ table , String $ CSVFile ) l
Bool update ( String $ table = NULL , Array $ set = [] )
Bool delete ( String $ table = NULL )
Bool increment ( String $ table = NULL , Mixed  $ columns = [] , Int $ increment = 1 )
Bool decrement ( String $ table = NULL , Mixed $ columns = [] , Int $ decrement = 1 )
this query ( String $ query , Array $ secure = [] )
this basicQuery ( String $ query , Array $ secure = [] )
Bool execQuery ( String $ query , Array $ secure = [] )
Bool multiQuery ( String $ query , Array $ secure = [] )

 

 

# Select General Syntax


The general syntax for how ZN's database selection methods can be used is shown below. The methods shown as [...] before the get () method can be interchanged among them .

DB :: [ select ( ... $ columns ) | sum ( $ column , 'as column name' ) | count ( $ column , 'as column name' ) ...]
   -> [ distinct () | distinctRow () | maxStatementTime ( $ time ) | straightJoin () | highPriority () | lowPriority () | quick () | delayed () | ignore () | smallResult () | bigResult () |bufferResult () | cache () | nocache () | calcFoundRows () ]
   -> [ where ( $ column , $ value , $ cond ) | Having (where ( $ column , $ value , $ cond ) ]
   -> [ wheregroup ( Array  ... $ where ) | havinggroup ( Array  ... $ having ) ]
   -> [ OrderBy ( $ column , $ type ) | GroupBy ($ column ) ]
   -> [ limit ( $ start , $ count ) ]
   -> [ join ( $ table , $ cond , $ type ) | type ( $ tableColumn , $ otherTableColumn ) >type (left, right, inner)]
   -> [ union ( $ table ) | unionAll ( $ table ) ]
   -> [partition ( ... $ args )| procedure ( ... $ args )| outFile ( $ file ) | dumpFile () | into ( $ varname1 , $ varname2 ) | forUpdate () | lockInShareMode () ]
   -> get ( $ table )
   -> [ row () | result () | resultArray () | resultJson () | value () | totalColumns () | totalRows () | columns () | columnData () | pagination () | fetchArray () |fetchAssoc () | fetchRow () | fetch () ]

 

 

# Select ( ZN >= 0.0.1 )


SQL is the equivalent of the SELECT statement. Usage is not compulsory. This method is used if data are required from certain colonies.

Parameters
String ... $ columns = '*' Columns desired to be obtained as a result of the selection.
return this
Usage
DB::select('id', 'name', 'address')->get('users');

echo DB::stringQuery();
SELECT id, name, address FROM users 

There is no need to use select () if all columns are to be retrieved

$users = DB::get('users');

output($users->result());

 

 

# Where ( ZN >= 0.0.1 )


SQL is the equivalent of the WHERE clause. Usage is not compulsory. It is used when transactions must be based on certain conditions.

Parameters - Single Form
String $ Columnname Column name.
String $ Value Column value.
String $ logical = NULL Conjunctions.
Options AND , OR
return this
Parameters - Multiple Form
Array $ columnandvalues Columns and values.
return this
Usage

Equality in control = operator does not have to be used.

$get = DB::where('id', 1)->get('users');

echo $get->stringQuery();

Operators must be used in comparisons outside the equality situation.

$get = DB::where('id !=', 1)->get('users');
Multiple Condition

You can use more than one where () in the linker.

$get = DB::where('id', 1, 'and')
         ->where('name !=', 'ZN', 'or')
         ->where('name !=', 'ZN4')
         ->get('users');

echo $get->stringQuery();
SELECT *
FROM users
WHERE id = '1' and name! = 'ZN' or name! = 'ZN4'
Array Usage

The first parameter for where () may contain the array data type. This use is where you need to send the where () method in more than one conditional array.

$get = DB::where
       ([
           ['id', 1, 'and'],
           ['name !=', 'ZN', 'or'],
           ['name !=', 'ZN4']
       ])
       ->get('users');

output($get->result());

echo $get->stringQuery();
SELECT *
FROM users
WHERE id = '1' and name! = 'ZN' or name! = 'ZN4'
Cycles ( ZN >= 4.2.8 )

The purpose of the conversions was to provide both data security and to allow some usage.

Int

To convert the column value to integer (integer) ;

echo DB::where('int:columnName', 'Example')->string()->get('tableName');
SELECT * FROM tableName WHERE columnName = 0

float

To convert a column value to a decimal number ( float ) ;

echo DB::where('float:columnName', 'Example')->string()->get('tableName');
SELECT * FROM tableName WHERE columnName = 0

Expression

To convert the column value to nil;

echo DB::where('exp:columnName', 'Example')->string()->get('tableName');
SELECT * FROM tableName WHERE columnName = Example

is used.

 

 

# WhereColumnNameCondition ( ZN >= 5.2.0 )


This special WHERE use is designed to create the desired WHERE structure without using extra parameters according to the desired column name and connector type . The method name is used to specify the desired column and any other WHERE structure to be joined, specifying the name of the connector.

Parameters
scaler $ Value Column value.
return this  
Usage
$blog = DB::whereIdAnd(1)->whereName('example')->blog()->row();

output($blog);

 

 

# WhereGroup ( ZN >= 3.0.0 )


If more than one condition is used, it must be grouped so that the condition can be formed correctly. In this method, the work you do is to group by taking in more than one conditional braces.

Parameters
Array $ Columnname Columns and their values.
return this  
Usage
$get = DB::whereGroup
(
    ['id', 1, 'or'],
    ['id', 2],
    'and'
)
->whereGroup
(
    ['name', 'ZN', 'and'],
    ['address', 'Istanbul']  
)
->get('users');

echo $get->stringQuery()
SELECT *
FROM users
WHERE (id = '1' it was = '2' ) and (name = 'Permit' and address = 'Istanbul' )

 

 

# Having ( ZN >= 0.0.1 )


SQL is the equivalent of the HAVING statement. Usage has the same logic as where () .

Parameters - Single Form
String $ Columnname Column name.
String $ Value Column value.
String $ logical = NULL Conjunctions.
Options AND , OR
return this  
Parameters - Multiple Form
Array $ columnandvalues Columns and values
return this  

 

 

# HavingGroup ( ZN >= 3.0.0 )


Usage is the same logic as whereGroup () .

Parameters
Array $ Columnname Columns and their values.
return this  

 

 

# GroupBy ( ZN >= 0.0.1 )


This is the counterpart of the SQL GROUP BY statement. The time is used to group in the query.

Parameters
Array $ Columnname Colonial name.
return this  
Usage
echo DB::groupBy('name')->string()->get('users'); 
SELECT * FROM users GROUP BY name
Note: DB :: string () returns the string output of the query .

 

 

# OrderBy ( ZN >= 0.0.1 )


It is the counterpart of the SQL ORDER BY statement. The time to sort in the query is used.

Parameters
String $ columna Column name.
String $ Type Sort type.
return this  
Usage
echo DB::orderBy('id', 'DESC')->where('id >', 10)->string->get('users');
SELECT * FROM users WHERE id> '10' ORDER BY id desc 

 

 

# Limit ( ZN >= 0.0.1 )


SQL is the LIMIT statement. The time to limit the query results is used.

Parameters
scaler $ start Limitlemeye will begin with the record number. The second parameter is used to specify the limit if not used. This parameter can be NULL if used with the DB :: pagination () method .
Int $ limit How many records will be shown.
return this
Usage
echo DB::limit(10)->string()->get('users');
SELECT * FROM users LIMIT 10
echo DB::limit(5, 10)->string()->('users');
SELECT * FROM users LIMIT 5 , 10

 

 

# Get ( ZN >= 0.0.1 )


This method is the final or final method that will result in the SELECT query being processed . A SELECT query get () by the method after the completion of  2 get () method must be implemented before the Usage strong query results. After this method, you can use only the result methods that will take the SELECT data.

Parameters
String $ Tablename Table name.
return this
Usage
$get = DB::where('id !=', 1)->orderBy('date', 'ASC')->get('users');

After the SELECT query completed with DB :: get () , the data for this query becomes available .  

$get     = DB::get('products');

$row     = $get->row();
$columns = $get->columns();
Single Use ( ZN >= 5.4.6 )

If you want to use the get () method without passing a variable or using it in a loop, you can use the basic () optional method if you do not want to recreate the query in each loop . You can not use this method if you plan to transfer a get () method to a variable . 

output(DB::basic()->get('users')->resuılt());
output(DB::basic()->get('users')->row());

This applies to uses that have been completed with output methods as outlined above.

 

 

# TableNameGet ( ZN >= 5.2.0 )


As with the specified version -> get ( 'tablename' ) instead of the method -> Tablename () it may be used. That is, the name of the table to be directly accessed is made available as a method.

Parameters
void
return Object
Usage
$ticket = DB::ticket();
$blog = DB::blog();

 

 

# Result ( ZN >= 0.0.1 )


SELECT is the method that returns query results in the form array, object, or json. The predefined value is the object type.

Parameters

Parameters
String $ outputType = 'object' If the parameter is changed in the table , the return type is object .
oBJECT The loop results in reaching the column value in each record in the form $ row -> columnName.
array The loop allows the results to be reached in the form $ row [ 'columnName' ] to reach the column value in each record .
json It allows the results to be brought in json form.
return Mixed
Usage
$get = DB::limit(10)->get('users');

foreach( $get->result() as $result )
{
    \Output::writeLine('ID:{0} - Name:{1}', [$result->id, $result->name]);
}

To get the results in an array type;

$get = DB::limit(10)->get('users');

foreach( $get->result('array') as $result )
{
    \Output::writeLine('ID:{0} - Name:{1}', [$result['id'], $result['name']]);
}

 

 

# ResultArray ( ZN >= 0.0.1 )


Gets query results in array type. It is the same as using DB :: result ( 'array' ) .

Parameters
void
return Array
Usage
echo DB::limit(10)->get('users')->resultArray();

 

 

# ResultJson ( ZN >= 0.0.1 )


Gets query results in the form of a json string.

Parameters
void
return String
Usage
echo DB::limit(10)->get('users')->resultJson();

 

 

# TableNameResult ( ZN >= 5.2.0 )


It is a practical use to retrieve records belonging to the table using the table name.

Parameters
String $ outputType = 'object' If the parameter is changed in the table , the return type is object .
oBJECT The loop results in reaching the column value in each record in the form $ row -> columnName.
array The loop allows the results to be reached in the form $ row [ 'columnName' ] to reach the column value in each record .
json It allows the results to be brought in json form.
return Mixed
Usage
$result = DB::blogResult();
$result = DB::ticketResult();

 

 

# Row ( ZN >= 0.0.1 )


Single line data object is used to get kind. Returns the value of both the array and the string according to the condition of the parameter .

Parameters
String $ type = 0 How many records will be taken.
1 , 2, .... -1 Which indexed record will be taken. A negative value can be given to bring the record from the probe.
true If the parameter takes a true value, the select (possibly id) value of the first column
return Object
Usage
$get = DB::get('users');
$row = $get->row();

echo $row->id . ' - ' . $row->name;
Registration Indie

You can give the record index to the parameter.

output($get->row(-1)); // Last row
output($get->row(0));  // First row
output($get->row(1));  // 2. row
Selected Column Value

You can output the value of the first column of the first record by giving the parameter true value.

echo $get->row(true); // First select column value

 

 

# TableNameRow ( ZN >= 5.2.0 )


It is a practical use created to retrieve a single row record of the table using the table name.

Parameters
void
return Object
Usage
$blogRow = DB::blogRow();
$ticketRow = DB::ticketRow();

 

 

# Value ( ZN >= 3.0.0 )


Returns the value of the first column of the record of the query result. DB :: row ( true ) does the work of the method.

Parameters
void
return String
Usage
echo DB::where('id', 1)->select('name')->get('users')->value();
echo DB::select('sum(price)')->get('users')->value();

This method is especially designed for use as in the second example .

Short Use ( 5.2.0 )

From a shorter path you can reach a single column value as follows.

echo DB::whereId(1)->usersRowName();

 

 

# TotalRows ( ZN >= 0.0.1 )


Query result gives the total number of records.

Parameters
Bool $ realLimit = false Number of records. If the parameter is set to true, it is not affected by the Usage LIMIT and returns the number of records.
return Int
Usage
echo DB::get('users')->totalRows();               # 100
echo DB::limit(5)->get('users')->totalRows();     # 5
echo DB::limit(5)->get('users')->totalRows(true); # 100
Actual Number of Records

2. If the parameter is set to true , LIMIT in the query does not prevent the actual number of records from being reached.

echo DB::limit(5)->get('users')->totalRows(true); # 100

 

 

# TotalColumns ( ZN >= 0.0.1 )


The query result table gives the number of columns.

Parameters
void
return Int
Usage
echo DB::get('users')->totalColumns();

 

 

# Columns ( ZN >= 0.0.1 )


Query end gives table columns in array type.

Parameters
void
return Array
Usage
output( DB::get('users')->columns() );

 

 

# ColumnData ( ZN >= 0.0.1 )


The query gives the results of table columns and columns. If no parameter is specified, all columns are given only the specified column information if the parameter is specified.

Parameters
String $ column = NULL The sequence of information about the columns turns. If no parameter is specified, the information columns of all columns are returned.
return Array String name Column name.
Int type Kind.
Int Maxlength Column length.
Int primaryKey Primary key.
String default Default.
Usage
$get = DB::get('users');

output($get->columnData());
output($get->columnData('id'));

 

 

# TableName ( ZN >= 2.0.0 )


It gives the name of the table used in the previous question.

Parameters
void
return String
Usage
$users = DB::users();

echo DB::tableName();
users

 

 

# Pagination ( ZN >= 2.0.0 )


According to our query, a paging bar is created. Because it is shaped according to the query, you will have to do a much simpler pagination process than you need to use the Pagination class. It is necessary to use limit () method for counting . The following file is used for the display configurations for paging.

Configuration: Config / ViewObjects.php -> pagination
Parameters
String $ url = NULL Where to insert the page registration number. If NULL is specified, it is appended to the end of the active URL.
Array $ config = [] Used to make the configuration as a parameter instead of a file.
return String
Usage
$get = DB::limit(NULL, 10)->get('users');

output($get->result());
output($get->pagination());
URL Parameter

If the pagination () method does not specify a parameter, it processes through the current URL and the paging related record number is appended to the URL. If the last part of the URL is not the record number information , you need to specify the URL to the 1st parameter. In the following example, if the registration number information is not at the end of the URL, the first parameter of pagination () method is used.

output($get->pagination('products/'.URI::segment(2).'/order/asc'));
Parametric Configuration

If you want to set the paging settings directly as a parameter instead of the config file. The second parameter of the pagination () method is used .

output($get->pagination(NULL, ['prevName' => 'prev', 'nextName' =>'next']));

 

 

# Status ( ZN >= 2.0.0 )


It gives information about the status of the corresponding sheet.

Parameters
String $ Table Table name.
return this
Usage
output( DB::status('users')->row() ); 
Array Values
Name            => string 'users' ( length = 5 ),
Engine          => string 'InnoDB' ( length = 8 ),
Version         => string '10' ( length = 4 ),
Row_format      => string 'Compact' ( length = 9 ),
Rows            => string '4' ( length = 3 ),
Avg_row_length  => string '4096' ( length = 6 ),
Data_length     => string '16384' ( length = 7 ),
Max_data_length => string '0' ( length = 3 ),
Index_length    => string '0' ( length = 3 ),
Data_free       => string '0' ( length = 3 ),
Auto_increment  => string '34' ( length = 4 ),
Create_time     => string '2016-08-18 17:28:53' ( length = 21 ),
Update_time     => NULL ( length = 0 ),
Check_time      => NULL ( length = 0 ),
Collation       => string 'utf8_general_ci' ( length = 15 ),
Checksum        => NULL ( length = 0 ),
Create_options  => string '' ( length = 2 ),
Comment         => string '' ( length = 2 )

 

 

# IsExists ( ZN >= 4.6.0 )


It checks whether the column has the specified column and value. If the value is true, otherwise it returns false .

Parameters
String $ Table Table name.
String $ columna Column name.
String $ Value Value.
return Bool
Usage
if( DB::isExists('Users', 'name', 'John') )
{
     # Your codes...
}

 

 

# Insert ( ZN >= 0.0.1 )


SQL INSERT is the equivalent of the INTO TABLE VALUES statement. Used to add record. The insertion process is quite easy.

Parameters
String $ Table Table name.
Mixed $ data Included.
return this
Usage
DB::insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);
Optional Methods
this duplicateCheck ( String ... $ args )
this duplicateCheckUpdate ( String ... $ args )
Again Disabled

The duplicateCheck () method is used to prevent this if the previously added data has already been registered . If it is desired to control specific columns, the parameter can be specified in order.

DB::duplicateCheck()->insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);

Let's check the plain name column.

DB::duplicateCheck('name')->insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);

If the column values ​​are the same according to the conditions specified above, the operation returns false .

The duplicateCheckUpdate () method is used if you have the same columns and want to update it instead of the insert .

DB::duplicateCheckUpdate()->insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);
Repeat Change

Let's check the plain name column. If the name column was previously saved with the same value, that data is updated.

DB::duplicateCheckUpdate('name')->insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);

If the column values ​​are the same according to the conditions specified above, the operation is updated and returns true if update is successful .

Optional Usage

You can also insert column values ​​as follows.

DB::column('name', 'NewName')
  ->column('address', 'NewAddress')
  ->insert('users');
Automatic Matching ( ZN >= 4.3.0 )

To automatically match and register the data in a sequence or method from the Form to the columns, the table name is ignored: the prefix is ​​fetched.

DB::insert('ignore:users', Method::post());
DB::insert('ignore:users', Method::get());
Post Post ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the POST method, matching the column names. With this method, recording is added in a very simple way without having to use the 2nd parameter.

DB::insert('post:users');
Data Manipulation

If you want to add value yourself to the POST string, you can use it as follows.

Post::add_date(date('Y-m-d-h-i-s'));
Post::ip(User::ip());

DB::insert('post:users');

The above applies to other methods of transmission.

Get Send ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the GET method, matching the column names. With this method, recording is added in a very simple way without having to use the 2nd parameter.

DB::insert('get:users');
Request Send ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the REQUEST method, matching the column names. With this method, recording is added in a very simple way without having to use the 2nd parameter.

DB::insert('request:users');

 

 

# TableNameInsert ( ZN >= 5.2.0 )


Used to insert data by table name.

Parameters
Array $ data Included.
return Bool
Usage
DB::usersInsert(['name' => 'micheal']);

 

 

# InsertID ( ZN >= 1.0.0 )


Returns the id value of the last record added. It is usually used in situations where it is necessary to perform an operation after an append using the id of the corresponding record.

Parameters
void
return Int
Usage
DB::insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);

echo DB::insertID(); # 37

 

 

# AffectedRows ( ZN >= 0.0.1 )


Returns the number of records affected by the last query operation. This process results in situations that affect records such as an insert, delete, update.

Parameters
void
return Int
Usage
DB::insert('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);

echo DB::affectedRows(); # 1

 

 

# InsertCSV ( ZN >= 5.3.9 )


CSV Used to insert columns and values ​​in the file into the table. For this, it must consist of the top line column names of the CSV file.

Sample CSV File

+ ----------------------------------------------------------------------- +
| users_file.csv                                                          |
+ ---- + ---------------- + --------------------------- + --------------- +
| id   | name             | address                     | phone           |
+ ---- + ---------------- + --------------------------- + --------------- +
| 1    | Micheal          | Italy                       | 12345           |
+ ---- + ---------------- + --------------------------- + --------------- +
| 2    | Susan            | France                      | 54321           |
+ ---- + ---------------- + --------------------------- + --------------- +

Parameters
String $ Table The table name to save.
String $ file The path to the CSV file. The extension is not written.
return Bool
Usage
DB::insertCSV('users', 'users_file');

 

 

# Update ( ZN >= 0.0.1 )


SQL UPDATE TABLE is the counterpart of the SET statement. Used to update contacts. It's simple to use.

Parameters
String $ Table Table name.
Mixed $ data Updated to be exported.
return Bool
Usage
DB::where('id', 1)->update('users',
[
    'name'    => 'NewName',
    'address' => 'NewAddress'
]);
Optional Usage

You can also update the column values ​​as follows.

DB::where('id', 1)
  ->column('name', 'NewName')
  ->column('address', 'NewAddress')
  ->update('users');
Automatic Matching ( ZN >= 4.3.0 )

To automatically match and update the data in a sequence or method from the Form to the columns, the table name is ignored: the prefix is ​​fetched.

DB::where('id', 1)->update('ignore:users', Method::post());
DB::where('id', 1)->update('ignore:users', Method::get());
Post Post ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the POST method, matching the column names. With this method, the registration update process is performed very simply without having to use the 2nd parameter.

DB::where('id', 1)->update('post:users');
Data Manipulation

If you want to add value yourself to the POST string, you can use it as follows.

Post::add_date(date('Y-m-d-h-i-s'));
Post::ip(User::ip());

DB::insert('post:users');

The above applies to other methods of transmission.

Get Send ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the GET method, matching the column names. With this method, the registration update process is performed very simply without having to use the 2nd parameter.

DB::where('id', 1)->update('get:users');
Request Send ( ZN >= 4.3.0 )

This allows you to automatically process values ​​that you have to send individually via the REQUEST method, matching the column names. With this method, the registration update process is performed very simply without having to use the 2nd parameter.

DB::where('id', 1)->update('request:users');

 

 

# TableNameUpdate ( ZN >= 5.2.0 )


Used to update data according to table name.

Parameters
Array $ data Updated to be exported.
return Bool
Usage
DB::whereId(1)->usersUpdate(['name' => 'micheal']);

 

 

# Delete ( ZN >= 0.0.1 )


This is the equivalent of the SQL DELETE FROM TABLE statement. Used to delete the record.

Parameters
String $ Table Table name.
return Bool
Usage
DB::where('id', 1)->delete('users');

 

 

# TableNameDelete ( ZN >= 5.2.0 )


It is used to delete data according to table name.

Parameters
void
return Bool
Usage
DB::whereId(1)->usersDelete();

 

 

# Increment ( ZN >= 2.0.0 )


It is used to increase the value of the specified columns in a table to the desired amount. The predefined increment value is 1.

Parameters
String $ Table The name of the table to be increased.
Mixed $ columna Column or columns to be increased.
Int $ count = 1 Increase the amount.
return Bool
Usage
DB::increment('users', 'activityCount');     // Increment 1
DB::increment('users', 'activityCount', 10); // Increment 10 
Multiple Increase

To make the same increase in more than one seat;

DB::increment('users', ['activityCount', 'loginCount'], '10'); // Increment 10

Above both the activityCount and loginCount columns are incremented by 10 .

 

 

# Decrement ( ZN >= 2.0.0 )


It is used to reduce the value of the specified columns in a table to the desired amount. The predefined reduction value is 1.

Parameters
String $ Table The name of the table to be reduced.
Mixed $ columna Column or columns to be reduced.
Int $ count = 1 Amount of reduction.
return Bool
Usage
DB::decrement('users', 'activityCount');     // Decrement 1
DB::decrement('users', 'activityCount', 10); // Decrement 10 
Multiple Reduction

To reduce at the same time in more than one seat;

DB::decrement('users', ['activityCount', 'loginCount'], '10'); // Decrement 10

Above both activityCount and loginCount columns are reduced by 10 .

 

 

# Query ( ZN >= 0.0.1 )


Used to write standard SQL queries. If the Usage this method is done on SELECT , you can get the data by using methods like result () , row () . That is, all of the output methods available after the get () method can be used. Since standard SQL queries are vulnerable to injection attacks, they should not be used in places where SQL injections can be performed externally . You are advised not to use it unless you have to. If you have to use it, be sure to use the secure () method for security .

Parameters
String $ query SQL query.
return this
Usage
$query = DB::query('SELECT * FROM users');
output($query->result());
Security Filter

Usage security secure () method;

Decisive Use
DB::secure([':x' => 1, ':y' => 'ZN'])
  ->query('SELECT * FROM users WHERE id = :x or name = :y');
Sequential Usage
DB::secure([1, 'ZN'])
  ->query('SELECT * FROM users WHERE id = ? or name = ?')

On this count you have specified the data you want the filter to be passed through.

 

 

# BasicQuery ( ZN >= 4.3.5 )


Used to run standard SQL query.

Parameters
String $ query SQL query.
return this
Usage
$query = DB::basicQuery('SELECT * FROM ExampleTable');

output($query->result());

 

 

# ExecQuery ( ZN >= 0.0.1 )


It is used for one-time executable queries. They can not be used with result retrieval queries containing SELECT statements. It is recommended to use it with queries such as CREATE , INSERT , ALTER , DROP , DELETE . It is the same logic as the Usage the query () method.

Parameters
String $ query SQL query.
return Bool
Usage
DB::execQuery('DROP TABLE products');

 

 

# MultiQuery ( ZN >= 3.0.0 )


Used to run multiple queries. They can not be used with result retrieval queries containing SELECT statements. It is recommended to use it with queries such as CREATE , INSERT , ALTER , DROP , DELETE . It is the same logic as the Usage the query () method.

Parameters
String $ query SQL query.
return Bool
Usage
DB::multiQuery('DROP TABLE products; CREATE TABLE contact(...)');