1. Go to this page and download the library: Download davahome/database 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/ */
davahome / database example snippets
/**
* Select from database
*
* @param string $table
* @param array $where
*
* @return mixed
*/
public function select(string $table, array $where): mixed;
/**
* Update a row
*
* @param string $table
* @param array $values key=>value
* @param array $where key=>value where condition (will be combined using AND)
* @param bool $allowEmptyWhere
*
* @return mixed
* @throws \DavaHome\Database\DatabaseException
*/
public function update(string $table, array $values, array $where, bool $allowEmptyWhere = false): mixed;
/**
* Insert a new row
*
* @param string $table
* @param array $values key=>value
*
* @return mixed
*/
public function insert(string $table, array $values): mixed;
/**
* Let the database create a UUID
*
* @return string
*/
public function createUuid(): string;
/**
* Create and execute a prepared statement immediately
*
* @param string $statement
* @param array $inputParameters
* @param array $driverOptions
*
* @return mixed|\PDOStatement
*/
public function execute($statement, array $inputParameters = [], array $driverOptions = []): PDOStatement;
/**
* Set the isolation level
*
* @param string $isolationLevel
*
* @return bool
*/
public function setIsolationLevel(string $isolationLevel): bool;
use DavaHome\Database\Extension\DirectValue;
// The query will look like this: UPDATE `table` SET `last_updated` = NOW() WHERE `id` = 1
$db->update('table', ['last_updated' => new DirectValue('NOW()')], ['id' => 1]);
// The query will look like this: UPDATE `table` SET `count` = `count` + 1 WHERE `id` = 1
$db->update('table', ['count' => new DirectValue('`count` + 1')], ['id' => 1]);
use DavaHome\Database\Extension\CustomOperator;
// The query will look like this: SELECT * FROM `table` WHERE `count` >= 2
$db->select('table', ['count' => new CustomOperator('>=', 2)]);
// The query will look like this: SELECT * FROM `table` WHERE `last_updated` <= NOW()
$db->select('table', ['last_updated' => new CustomOperator('<=', new DirectValue('NOW()'))]);
bash
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.