Developer Center

EN

Create a Query

SELECT

It is written as WDB::select(arg1)

You can type the column names in arg1 or leave it blank.

Returns the class content as the return value.

FROM

It is written as WDB::from(arg1)

You must write the table name inside arg1 

Returns the class content as the return value.

JOIN

It is written as WDB::join(arg1,arg2,arg3) 

One of the values of "INNER" , "LEFT" , "RIGHT" , "FULL OUTER" must be written inside arg1

The table name must be written inside arg2

Conditions must be written inside arg3

Returns the class content as the return value.

Sample PHP Code


<?php
    $query = WDB::select("t1.id,t1.field1,t1.field2,t2.field1 AS 'field_1' ");
    $query->from("table1 t1");
    $query->join("LEFT","table t2","t2.relid = t1.id");
    $query = $query->build(true)->fetch_assoc();
    print_r($query);
?>
Output

SELECT t1.id,t1.field1,t1.field2,t2.field1 AS 'field_1' FROM table1 t1 LEFT JOIN table2 t2 ON t2.relid = t1.id
-----------
Output: 
Array
(
    [0] => Array
        (
            [id] => 1
            [field1] => sample1
            [field2] => sample2
            [field_1] => sample test
        )

)

WHERE

It is written as WDB::where(arg1,arg2,arg3,arg4)

Write the name of the column inside arg1

Sign value should be written inside arg2. Example: ("LIKE" , "NOT LIKE" , "=" , "!=" , etc...)

You must write the value to match in arg3. (If you're using a LIKE condition, you can also use "%" in the value to match.)
You can write a logical operator in arg4.For example: ( "AND" ,  "OR" , "&&" , "||" etc...)

Returns the class content as the return value.

GROUP BY

It is written as WDB::group_by(arg1)

The column name should be written inside arg1

Returns the class content as the return value.

ORDER BY

It is written as WDB::order_by(arg1)

The column name should be written inside arg1

Returns the class content as the return value.

LIMIT

It is written as WDB::limit(arg1,arg2)

You can write the initial value in arg1 and the limit value in arg2

If you define a value only in arg1, the limit value is defined.

Returns the class content as the return value.

BUILD

It is written as WDB::build(arg1)

A boolean value must be defined in arg1. By default, "false" is defined.

The purpose of the method is to collect the query and send a request to the database after the methods mentioned above are defined.

If you define "true" in arg1, it will return the class content as return.

If you enter "false" in arg1, it returns the status of the query as "boolean" in the return information.

FETCH_ASSOC

It is written as WDB::fetch_assoc()

The intended use of the method is to list all the results in the "ARRAY" data type immediately after the "build" method runs.

FETCH_OBJECT

It is written as WDB::fetch_object()

The intended use of the method is to list all the results in the "OBJECT" data type immediately after the "build" method runs.

getAssoc

It is written as WDB::getAssoc()

The intended use of the method is to list all the results in the "ARRAY" data type immediately after the "build" method runs.

getObject

It is written as WDB::getObject()

The intended use of the method is to list all the results in the "OBJECT" data type immediately after the "build" method runs.

Sample PHP Code


<?php
    $query = WDB::select("t1.id,t1.field1,t1.field2,t2.field1");
    $query->from("table1 t1");
    $query->join("LEFT","table t2","t2.relid = t1.id");
    $query->where("t1.field1","=","apple","||");
    $query->where("t1.field1","=","pear");
    $query->group_by("t1.id");
    $query->order_by("t1.field1 DESC");
    $query->limit(0,10);
    $result = $query->build();
    if($result)
    {
        print_r(WDB::fetch_assoc());
    }
    else
    {
        echo "No result found";
    }
    
?>
Output

SELECT t1.id,t1.field1,t1.field2,t2.field1 AS 'field_1' FROM table1 t1 LEFT JOIN table2 t2 ON t2.relid = t1.id WHERE t1.field1 = 'apple' OR t1.field1 = 'pear' GROUP BY t1.id ORDER BY t1.field1 DESC LIMIT 0,10
-----------
Output: 
Array
(
    [0] => Array
        (
            [id] => 1
            [field1] => apple
            [field2] => sample2
            [field_1] => sample test
        )

)
 
Introduction INSERT

Do you have any questions?

Feel free to contact us
Contact Us
Copyright © 2021. All rights reserved.
Join Our Discord Channel
Top