PHP code example of emmanix2002 / database-adapter

1. Go to this page and download the library: Download emmanix2002/database-adapter 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/ */

    

emmanix2002 / database-adapter example snippets


use Emmanix2002\MySqlAdapter;

MySqlAdapter::setDefault('host', 'default_hostname');
MySqlAdapter::setDefault('schema', 'default_schema');
MySqlAdapter::setDefault('user', 'default_user');
MySqlAdapter::setDefault('password', 'default_password');

$adapterDefault = MySqlAdapter::create();
// create an adapter using the defaults

$adapter = MySqlAdapter::create(['host' => 'another_hostname']);
// equivalent to new MySqlAdapter('another_hostname', 'default_schema', 'default_user', 'default_password');

$sql = 'SELECT * FROM `users` WHERE `user_email`=? AND `user_status`=?';
$record = $adapter->selectOne($sql, '[email protected]', 1);

// it is also possible to do the same like so:
$args = ['[email protected]', 1];
$record = $adapter->selectOne($sql, ...$args);

// both will return the same value

 php
$config = ['host' => 'localhost', 'user' => 'user', 'password' => 'password', 'schema' => 'schema_name'];

$adapter = Emmanix2002\MySqlAdapter::create($config);
// OR
$adapter = new Emmanix2002\MySqlAdapter('host', 'schema_name', 'user', 'password');

$record = $adapter->selectOne('SELECT * FROM `Users` WHERE `user_id`=?', 21134);
var_dump($record);