PHP code example of adrian0350 / simple-pdo-wrapper

1. Go to this page and download the library: Download adrian0350/simple-pdo-wrapper 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/ */

    

adrian0350 / simple-pdo-wrapper example snippets




 = array(
	'database' => 'your_db_name',
	'username' => 'root',
	'password' => 'toor',
	'host' => 'localhost'
);
$SimplePDOWrapper = new SimplePDOWrapper($conf);

// For now conditions only has basic clause.
$options = array(
	'conditions' => array(
			'username' => '[email protected]'
		),
	'limit' => 10,
	'fields' => array('id', 'username', 'password', 'name'),
	'order' => array('id DESC')
);

// When updating it will only return true or false.
$update = array(
	'name' => 'Adrián Zúñiga'
);
$SimplePDOWrapper->update('users', $update, array(
	'conditions' => array(
		'id' => $user_saved['id']
	)
));

// This findOne will return the one entity array or empty array.
$user = $SimplePDOWrapper->findOne('users', $options, $assoc = true);

// And findAll will return empty array or an array of STDClass objects.
$users = $SimplePDOWrapper->findAll('users', $options, $assoc = false);

// Options just needs compliant conditions.
$options = array(
    'conditions' => array(
        'id' => 666
    )
);

// Boolean
$deleted = $this->SimplePDOWrapper->delete('users', $options);

// Boolean
$deleted = $this->SimplePDOWrapper->deleteAll('users');

// Switch database with setDatabase() method
// and pass credentials in $conf array.
$conf = array(
	'database' => 'another_db',
	'username' => 'root',
	'password' => 'toor',
	'host' => 'localhost'
);

// Will return boolean.
$SimplePDOWrapper->setDatabase($conf);