PdoOne
It is a simple library for PHP that simplify the use of the PDO extension.
Install / Use
/learn @EFTEC/PdoOneREADME
Database Access Object wrapper for PHP and PDO in a single class
PdoOne. It's a simple wrapper for PHP's PDO library compatible with SQL Server (2008 R2 or higher), MySQL (5.7 or higher) and Oracle (12.1 or higher).
This library tries to work as fast as possible. Most of the operations are simple string/array managements and work in the bare metal of the PDO library, but it also allows to create an ORM using the extension eftec/PdoOneORM.
Turn this
$stmt = $pdo->prepare("SELECT * FROM myTable WHERE name = ?");
$stmt->bindParam(1,$_POST['name'],PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->get_result();
$products=[];
while($row = $result->fetch_assoc()) {
$product[]=$row;
}
$stmt->close();
into this
$products=$pdoOne
->select("*")
->from("myTable")
->where("name = ?",[$_POST['name']])
->toList();
or using the ORM (using eftec/PdoOneORM library)
ProductRepo // this class was generated with echo $pdoOne()->generateCodeClass(['Product']); or using the cli.
::where("name = ?",[$_POST['name']])
::toList();
Table of contents
<!-- TOC -->- Database Access Object wrapper for PHP and PDO in a single class
- Table of contents
- Examples
- Installation
- How to create a Connection?
- How to run a SQL command?
- How to work with Date values?
- How to run a transaction?
- Custom Queries
- tableExist($tableName)
- statValue($tableName,$columnName)
- columnTable($tablename)
- foreignKeyTable($tableName)
- createTable($tableName,$definition,$primaryKey=null,$extra='',$extraOutside='')
- tableSorted($maxLoop = 5, $returnProblems = false, $debugTrace = false)
- validateDefTable($pdoInstance,$tablename,$defTable,$defTableKey)
- foreignKeyTable
- Query Builder (DQL)
- toPdoStatement($pdoMode)
- fetchLoop($callable,$pdoMode)
* toMeta()
* toListSimple()
* toListKeyValue()
* toResult()
* firstScalar($colName=null)
* first()
* last()
* sqlGen()
- Query Builder (DML)
- Cache
- Sequence
- Fields
- Encryption
- How to debug and trace errors in the database?
- CLI
- Benchmark (mysql, estimated)
- migration from 3 to 4
- Error FAQs
- Changelist
Examples
| ExampleTicketPHP | Example cupcakes | Example Search | Example Different Method | |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------| | <img src="https://camo.githubusercontent.com/3c938f71f46a90eb85bb104f0f396fcba62b8f4a/68747470733a2f2f74686570726163746963616c6465762e73332e616d617a6f6e6177732e636f6d2f692f3436696b7061376661717677726533797537706a2e6a7067" alt="example php bladeone" width="200"/> | <img src="https://github.com/EFTEC/example.cupcakes/raw/master/docs/result.jpg" alt="example php bladeone cupcakes" width="200"/> | <img src="https://github.com/EFTEC/example-search/raw/master/img/search_bootstrap.jpg" alt="example php bladeone search" width="200"/> | <img src='https://github.com/escuelainformatica/example-pdoone/raw/master/docs/database.jpg' width=200 /> |
More examples:
Example Mysql PHP and PDO using PDOOne
Installation
This library requires PHP 7.1 and higher, and it requires the extension PDO and the extension PDO-MYSQL (Mysql), PDO-SQLSRV (sql server) or PDO-OCI (Oracle)
Install (using composer)
Edit composer.json the next requirement, then update composer.
{
"require": {
"eftec/PdoOne": "^4.0.1"
}
}
or install it via cli using
composer require eftec/PdoOne
Install (manually)
Just download the folder lib from the library and put in your folder project.
