PHP code example of alexdremov / daim

1. Go to this page and download the library: Download alexdremov/daim library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexdremov / daim example snippets


use DAIM\Core\Connection;
use DAIM\Core\Credentials;

$cred = new Credentials();
$cred->setHost(host);
$cred->setUsername(username);
$cred->setDBname(DBname);
$cred->setPassword(password);
$cred->setPort(port);

Connection::setCredentials($cred);
Connection::initConnection();

Connection::getConnection(); # returns active MySQL connection (instance of mysqli class);

# To set up a second connection (maybe to the second database),
# you can create additional connection mode:

/**
 * Set up $cred2 as instance of Credentials class for the second connection
 * @var $cred2 Credentials;
 */

Connection::setCredentials($cred2, "secondConnectionName");
Connection::initConnection("secondConnectionName");

// Basic raw query.
Connection::query('SELECT * FROM `Persons` WHERE 1', "secondConnectionName");

use DAIM\Core\QueryBuilder;
use DAIM\Syntax\SQLEntities\Conditions;

$qb = new QueryBuilder();
$result = $qb->select('*')->from('Information')->request();

# Or more complicated usage:

$result = $qb->select(
    'Persons.LastName', 'Persons.PersonID', 'Information.Tel'
)->from(
    'Information', 'Persons'
)->where(
    (new Conditions())->field('Information.PersonID')->equal()->field('Persons.PersonID')
)->request();

# Generates SQL
# SELECT Persons.LastName, Persons.PersonID, Information.Tel FROM Information, Persons WHERE Information.PersonID = Persons.PersonID
# final ->request() returns instance of QueryResult class.

use DAIM\Core\QueryBuilder;

$qb = new QueryBuilder();

$qb->insertInto('tableName', array(
"field1"=>"value1",
"field2"=>"value2"
));
$response = $qb->request(); // Commit changes

// Or longer version:

$qb->insertInto('tableName')->columns('field1', 'field2', 'field3')->values('value1', 'value2', 'value3')->request();
$qb->insertInto('tableName')->values('value1', 'value2', 'value3')->request();