Wiki
Clone wikiprep / Home
Welcome
Welcome on the prep's wiki! This should provide you the reference for the methods and the classes of the project, with examples to help you understand how to use it. I'm a student doing that project on my spare time, so you may find incomplete pages and information, hopefully that will be completed later.
If you ever find some mistakes, wrong info, bugs, English misusage or any other failure, please contact me! English is not my native language, please excuse my misspellings.
If you speack French, you might enjoy reading Le petit guide du débutant pour PREP
.
Manual
Please note that this manual is documented only for the last PREP version.
Reference
- The
Prep
class - The
prep
namespace
How to understand PREP?
The main interface to do action with PREP is the PHP class Prep
: it contains most of the functionalities you'll need to interact with a database. The prep
namespace contains all of the backend classes used by the Prep
class, you do not need to know how that works to use PREP.
Prep
's methods' names
It has the classic actions:
Prep::connect('database_name', 'user_name', 'user_password', 'mysql_server');
Prep::query('/* SQL stuff */');
And the shortcuts for the usual queries :
Prep::select
Prep::insert
Prep::update
Prep::delete
And you can combine them with suffixes such as one
, all
, init
:
Prep::selectAll
Prep::updateOne
- ...
Or with the prefix debug_
when you want to understand a bug:
Prep::debug_insert
Prep::debug_deleteOne
- ...
And if you want to inject some SQL statement into your query, use Prep::SQL
.
Prep
's methods' arguments
All of the methods of Prep
may receive their arguments in procedural way or in "jQuery way":
<?php // Procedural way Prep::selectAll('some_table', ['ID', 'name']); // "jQuery way" Prep::selectAll([ 'table'=>'some_table', 'fields'=>['ID', 'name'] ]); // Combining both way Prep::selectAll(['some_table', 'fields'=>['ID', 'name']]); ?>
Having trouble to handle to maintain SQL connection through functions and files?
PREP will do that for you (again)! You can set a default PDO
(or prep\PDO
or any other class that extends PDO
) to the main class Prep
, and every time you ask for a query, this connection will be used. To do so, it's very easy:
<?php Prep::$PDO = Prep::connect('db_name', 'user_name', 'mypass'); // Or if your SQL server is not on localhost, you can specify the server to use Prep::$PDO = Prep::connect('db_name', 'user_name', 'mypass', 'sqlserver.exemple.com'); ?>
For more detailed explanations and exemples, please read the reference of the methods.
Have fun!
Updated