yepsql / yepsql
This package is abandoned and no longer maintained.
No replacement package was suggested.
SQL templating helper for PHP inspired by yesql.
v0.2.0
2017-09-12 14:37 UTC
Requires
- php: >=5.4.0
- ext-pdo: *
Requires (Dev)
- phpunit/phpunit: 4.8
This package is not auto-updated.
Last update: 2023-11-03 06:22:56 UTC
README
SQL templating helper for PHP inspired by yesql.
Requirements: php >= 5.6; pdo_extension;
Install: composer require yepsql/yepsql
Usage
Create a file containing your SQL queries
File example:
-- name: sqlQueryName -- query annotation SELECT count(*) FROM `table`; -- name: getUsersInfo -- request annotation 1 ... -- request annotation 2 ... SELECT * FROM `table` WHERE `user_id` = ? ; -- name: updateUserName UPDATE `table` SET `user_name` = :user_name WHERE `user_id` = :user_id ;
And call them in your code. Notice: "query-name" is converted to "query_name", php does not support this name methods.
Example:
$sql_template = new \YepSQL\Builder( new PDO_instance('sqlite::memory:'), // you instance of PDO '/path/to/file.sql' // file with queries ); // prepare SELECT * FROM `table` WHERE `user_id` = ? ; // and send query "getUsersInfo": // SELECT * FROM `table` WHERE `user_id` = 128; $user_id = 128; // request arguments $stmt = $sql_template->getUsersInfo($user_id); // returned PDOStatement instance $user_data = $stmt->fetch(PDO::FETCH_ASSOC); // send query "updateUserName": // UPDATE `table` SET `user_name` = 'NewUSerName' WHERE `user_id` = '128'; $sql_template->updateUserName([ ':user_name' => 'NewUSerName', ':user_id' => 128 ]);
Enjoy.