Message-ID: <1042767533.10077.1710846744463.JavaMail.confluence@docs1> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_10076_786663243.1710846744463" ------=_Part_10076_786663243.1710846744463 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html db

db

Description


Core\Db db<= /strong>()


Access our database layer with the db() function. = It supports method chaining.

Examples


=20
<?php

// Run a query to get at least 10 users
$users =3D db()->select('*')
   ->from(':user')
   ->order('user_id ASC')
   ->limit(10)
   ->executeRows();
 
// Get a single user
$user =3D db()->select('*')->from(':user')->where(['user_id' =3D&g=
t; 1])->executeRow();
 
// Insert an entry into the DB
$insert_id =3D db()->insert(':user', ['user_name' =3D> 'Foo']);
 
// Update an entry in the DB
db()->update(':user', ['user_name' =3D> 'bar'], ['user_id' =3D> 1]=
);
 
// Get the total rows
$total =3D db()->select('COUNT(*)')->from(':user')->count();
 
// Joining tables
db()->select('f.*, b.*')
   ->from(':foo', 'f')
   ->join(':bar', 'b', 'b.id =3D f.id')
   ->executeRow();
=20

Methods


Method Description Usage Returns

select(string = $select)

 


$select

SQL Sel= ect

Select statement for sql query<= /p>

=20
// Method ch=
aining
->select('user_id, user_name')
 
// SQL equivalent
SELECT user_id, user_name
=20

object Core\Db

from(string $t= able [, string $alias] )

 


$table

Database= table name.


$alias

(optiona= l) Table alias.

 Define the table in your = SELECT query.

Table Prefix: Be sure to prefix tables with a colon.

=20
 // Met=
hod chaining
->from(':user', 'u')

// SQL equivalent
FROM prefix_user AS u
=20
object Core\Db

where(array $c= ondition)

 


$condition

SQL = condition in an ARRAY format.

Associative array of a conditio= nal statement.

Learn more = here.

=20
// Method ch=
aining
->where([
=09'user_name' =3D> 'Foo',
=09'full_name' =3D> 'Bar'
])
 
// SQL equivalent
WHERE user_name =3D "Foo" AND full_name =3D "Bar"
 
=20
object Core\Db

 

Conditional Array Statements

...

 

------=_Part_10076_786663243.1710846744463--