Incluir a classe xPdo.php em seu projeto.
require_once("xPdo.php");
require 'xPdo.php';
$config = [ 'host' => 'localhost', 'driver' => 'mysql', 'database' => 'test', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => '' ];
$db = new xPdo($config);
Parabéns! Agora você pode usar o xPdo.
Se você tiver um problema, você pode entrar em contato comigo.
- Encode/Decode
- Radom Hash
- Lat and Lng
- Limit Text
- Date Format
- Select
- Select Functions (min, max, sum, avg, count)
- Table
- get AND getAll
- join
- where - orWhere
- grouped
- in - notIn - orIn - orNotIn
- between - orBetween - notBetween - orNotBetween
- like - orLike
- groupBy
- having
- orderBy
- limit
- insert
- update
- delete
- analyze
- check
- checksum
- optimize
- repair
- query
- insertId
- numRows
- error
- cache
- queryCount
- getQuery
- escape - (Not yet)
# Enable openssl # Usage : string parameter, secret key $db->thor('encode', 'String', 'Secret Key'); $db->thor('decode', 'String', 'Secret Key');
# Usage : string parameter size to generate $db->get_hash('48');
# Usage : string parameter address $db->getLatLong('São Paulo, SP, Brazil');
# Usage : string parameter and number limit characters $db->text_limit('String','60');
# Usage : date and format / en = yyyy-mm-dd / br = dd/mm/yyyy $db->date('01/01/2018','en'); # Output: 2018-01-01
$db->datetime('01/01/2018 12:00:00','en');
$db->date('2018-01-01','br');
$db->datetime('01/01/2018 12:00:00','br');
# Usage 1: string parameter $db->select('title, content'); $db->select('title AS t, content AS c');
$db->select(['title', 'content']); $db->select(['title AS t', 'content AS c']);
# Usage 1:
$db->table('test')->max('price');
$db->table('test')->count('id', 'total_row');
# Usage 1: string parameter $db->table('table'); $db->table('table1, table2'); $db->table('table1 AS t1, table2 AS t2');
$db->table(['table1', 'table2']); $db->table(['table1 AS t1', 'table2 AS t2']);
# get(): return 1 record. # getAll(): return multiple records.
$db->table('test')->getAll(); // " SELECT * FROM test " $db->select('username')->table('users')->where('status', 1)->getAll(); // " SELECT username FROM users WHERE status = '1' "
$db->select('title')->table('pages')->where('id', 17)->get(); // " SELECT title FROM pages WHERE id = '17' LIMIT 1 "
$records = $db->table('test')->getAll(); foreach ((array) $records as $record) { echo $record->title; }
# Usage 1: $db->table('foo')->join('bar', 'foo.field', 'bar.field')->getAll(); $db->table('foo')->leftJoin('bar', 'foo.field', 'bar.field')->getAll(); $db->table('foo')->rightJoin('bar', 'foo.field', 'bar.field')->get(); $db->table('foo')->innerJoin('bar', 'foo.field', 'bar.field')->get();
$db->table('foo')->join('bar', 'foo.field', '=', 'bar.field')->getAll(); $db->table('foo')->leftJoin('bar', 'foo.field', '=', 'bar.field')->getAll(); $db->table('foo')->rightJoin('bar', 'foo.field', '=', 'bar.field')->get(); $db->table('foo')->innerJoin('bar', 'foo.field', '=', 'bar.field')->get();
# Usage 1: array parameter $where = [ 'name' => 'Burak', 'age' => 23, 'status' => 1 ]; $db->where($where);
$db->where('status', 2); $db->where('status', 1)->where('name', 'burak'); $db->where('status', 1)->orWhere('status', 2);
$db->where('age', '>', 20); $db->where('age', '>', 20)->orWhere('age', '<', 30);
$db->where('status = ? AND age = ?', [1, 20]); $db->where('status = ? AND title = ?', [0, 'example title']);
$db->table('users') ->grouped(function($q) { $q->where('country', 'TURKEY')->orWhere('country', 'ENGLAND'); }) ->where('status', 1) ->getAll();
$key = 10; $db->table('users') ->grouped(function($q) use ($key) { $q->where('key_field', $key)->orWhere('status', 0); }) ->where('status', 1) ->getAll();
$db->in('page', ['about', 'contact', 'products']);
$db->orIn('id', [1, 2, 3]);
$db->notIn('age', [20, 21, 22, 23]);
$db->orNotIn('age', [30, 31, 32, 32]);
$db->between('age', 10, 20);
$db->orBetween('age', 20, 30);
$db->notBetween('year', 2010, 2015);
$db->orNotBetween('year', 2005, 2009);
$db->like('title', '%burak%'); // " title LIKE '%burak%' " $db->like('title', 'humolot%'); // " title LIKE 'humolot%' " $db->like('title', '%humolot'); // " title LIKE '%humolot' "
$db->like('tag', '%php%')->orLike('tag', '%web%'); $db->like('tag', '%php%')->orLike('tag', 'web%'); $db->like('tag', '%php%')->orLike('tag', '%web');
# Usage 1: string parameter $db->groupBy('country'); $db->groupBy('country, city');
$db->groupBy(['country', 'city']);
$db->having('AVG(price)', 2000); // " AVG(price) > 2000 "
$db->having('AVG(price)', '>=', 3000); // " AVG(price) >= 3000 "
$db->having('SUM(age) <= ?', [50]); // " SUM(age) <= 50 "
$db->orderBy('id'); // " ORDER BY id ASC
$db->orderBy('id DESC');
$db->orderBy('id', 'desc');
$db->orderBy('rand()'); // " ORDER BY rand() "
$db->limit(10); // " LIMIT 10 "
$db->limit(10, 20); // " LIMIT 10, 20 "
$data = array( 'title' => 'test', 'content' => 'Lorem ipsum dolor sit amet...', 'time' => time(), 'status' => 1 );
OR
$data = array(); $data['title'] = 'test'; $data['content'] = 'Lorem ipsum dolor sit amet...'; $data['time'] = time(); $data['status'] = 1;
OR
$data = [ 'title' => 'test', 'content' => 'Lorem ipsum dolor sit amet...', 'time' => time(), 'status' => 1 ];
$db->table('pages')->insert($data);
$data = array( 'username' => 'humolot', 'password' => md5('demo-password'), 'activation' => 1, 'status' => 1 );
OR
$data = array(); $data['username'] = 'humolot'; $data['password'] = md5('demo-password'); $data['activation'] = 1; $data['status'] = 1;
OR
$data = [ 'username' => 'humolot', 'password' => md5('demo-password'), 'activation' => 1, 'status' => 1 ];
$db->table('users')->where('id', 10)->update($data);
$db->table('users')->where('id', 5)->delete();
$query = $db->table('users')->analyze();
var_dump($query);
$query = $db->table(['users', 'pages'])->check();
var_dump($query);
$query = $db->table(['users', 'pages'])->checksum();
var_dump($query);
$query = $db->table(['users', 'pages'])->optimize();
var_dump($query);
$query = $db->table(['users', 'pages'])->repair();
var_dump($query);
$ds = $db->query("SELECT * FROM test WHERE id = '10' AND status = '1'");
OR
$db->query('SELECT * FROM test WHERE id = ? AND status = ?', [10, 1]);
$data = array( 'title' => 'test', 'content' => 'Lorem ipsum dolor sit amet...', 'time' => time(), 'status' => 1 );
OR
$data = array(); $data['title'] = 'test'; $data['content'] = 'Lorem ipsum dolor sit amet...'; $data['time'] = time(); $data['status'] = 1;
OR
$data = [ 'title' => 'test', 'content' => 'Lorem ipsum dolor sit amet...', 'time' => time(), 'status' => 1 ];
$db->table('pages')->insert($data);
var_dump($db->insertId());
$db->select('id, title')->table('test')->where('status', 1)->orWhere('status', 2)->getAll();
var_dump($db->numRows());
$db->error();
# Usage: ...->cache($time)->...
$db->table('pages')->where('slug', 'example-page.html')->cache(60)->get(); // cache time: 60 seconds
$db->queryCount(); // The number of all SQL queries on the page until the end of the beginning.
$db->getQuery(); // Last SQL Query.