|
1 | | -**ezsql** |
2 | | -===== |
3 | | -[](https://travis-ci.org/ezSQL/ezSQL) |
4 | | -[](https://ci.appveyor.com/project/jv2222/ezsql/branch/master) |
5 | | -[](https://codecov.io/gh/ezSQL/ezSQL) |
6 | | -[](https://codeclimate.com/github/techno-express/ezSQL/maintainability) |
7 | | - |
8 | | -Introduction |
9 | | - |
10 | | -When working with databases most of the time you will want to do one of four types of basic operations. |
11 | | -1. Perform a query such as Insert or Update (without results) |
12 | | -2. Get a single variable from the database |
13 | | -3. Get a single row from the database |
14 | | -4. Get a list of results from the database |
15 | | - |
16 | | -**ezsql** wraps up these four basic actions into four very easy to use functions. |
17 | | - |
18 | | -bool $db->query(query) |
19 | | -var $db->get_var(query) |
20 | | -mixed $db->get_row(query) |
21 | | -mixed $db->get_results(query) |
| 1 | +# **ezsql** |
22 | 2 |
|
23 | | -With **ezsql** these four functions are all you will need 99.9% of the time. Of course there are also some other useful functions but we will get into those later. |
24 | | - |
25 | | -Important Note: If you use **ezsql** inside a function you write, you will need to put global $db; at the top. |
| 3 | +[](https://travis-ci.org/ezSQL/ezSQL) |
| 4 | +[](https://ci.appveyor.com/project/jv2222/ezsql/branch/v4) |
| 5 | +[](https://codecov.io/gh/ezSQL/ezSQL) |
| 6 | +[](https://codeclimate.com/github/techno-express/ezSQL/maintainability) |
26 | 7 |
|
27 | | -Description |
28 | | ------------- |
29 | | -Class to make it very easy to deal with database connections. |
| 8 | +***Class to make it very easy to deal with database connections.*** |
30 | 9 |
|
31 | | -· **ezsql** is a widget that makes it very fast and easy for you to use database(s) within your PHP scripts ( mysql/ postgreSQL / SQL Server/ SQLite3). |
| 10 | +This is [__version 4__](https://github.com/ezSQL/ezSQL/tree/v4) that has many modern programming practices in which will break users of version 3. |
32 | 11 |
|
33 | | -· It is one php file that you include at the top of your script. Then, instead of using standard php database functions listed in the php manual, you use a much smaller (and easier) set of **ezsql** functions. |
| 12 | +[__Version 3__](https://github.com/ezSQL/ezSQL/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features. |
34 | 13 |
|
35 | | -· It automatically caches query results and allows you to use easy to understand functions to manipulate and extract them without causing extra server overhead |
| 14 | +This library has an `Database` class, a combination of the [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern) pattern with an [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) container hosting. The library is following many OOP principles, one in which, properties public access has been removed. |
36 | 15 |
|
37 | | -· It has excellent debug functions making it lightning-fast to see what’s going on in your SQL code |
| 16 | + - More Todo... |
38 | 17 |
|
39 | | -· Most **ezsql** functions can return results as Objects, Associative Arrays, or Numerical Arrays |
| 18 | +For an full overview see [documentation Wiki](https://github.com/ezSQL/ezSQL/WIKI.md), which is not completely finish. |
40 | 19 |
|
41 | | -· It can dramatically decrease development time and in most cases will streamline your code and make things run faster as well as making it very easy to debug and optimise your database queries. |
| 20 | +## Installation |
42 | 21 |
|
43 | | -· It is a small class and will not add very much overhead to your website. |
44 | | - |
45 | | -Note: It is assumed that you are familiar with PHP, basic Database concepts and basic SQL constructs. Even if you are a complete beginner **ezsql** can help you once you have read and understood this tutorial. |
| 22 | + composer require ezsql/ezsql |
46 | 23 |
|
47 | | -Installation |
48 | | ------- |
49 | | -`composer require ezsql/ezsql` |
| 24 | +## Usage |
50 | 25 |
|
51 | | -`require 'vendor/autoload.php';` |
| 26 | +```php |
| 27 | +require 'vendor/autoload.php'; |
52 | 28 |
|
| 29 | +// '****' is one of **mysqli**, **pgsql**, **sqlsrv**, **sqlite3**, or **Pdo**. |
| 30 | +use ezsql\Database; |
53 | 31 |
|
54 | | -**[Authors/Contributors](https://github.com/ezsql/ezsql/CONTRIBUTORS.md)** |
55 | | ---- |
| 32 | +$db = Database::initialize('****', [$dsn_path_user, $password, $database, $or, $other_settings], $optional_instance_tag); |
56 | 33 |
|
57 | | -Quick Examples.. |
| 34 | +// Is same as: |
| 35 | +use ezsql\Config; |
| 36 | +use ezsql\Database\ez_****; |
58 | 37 |
|
59 | | -Note: In all these examples no other code is required other than including ez_sql.php |
60 | | - |
61 | | -Example 1 |
62 | | - |
63 | | -// Select multiple records from the database and print them out.. |
64 | | -$users = $db->get_results("SELECT name, email FROM users"); |
65 | | -foreach ( $users as $user ) |
66 | | -{ |
67 | | - // Access data using object syntax |
68 | | - echo $user->name; |
69 | | - echo $user->email; |
70 | | -} |
71 | | - |
72 | | -Example 2 |
73 | | - |
74 | | -// Get one row from the database and print it out.. |
75 | | -$user = $db->get_row("SELECT name,email FROM users WHERE id = 2"); |
76 | | -echo $user->name; |
77 | | -echo $user->email; |
78 | | - |
79 | | -Example 3 |
80 | | - |
81 | | -// Get one variable from the database and print it out.. |
82 | | -$var = $db->get_var("SELECT count(*) FROM users"); |
83 | | -echo $var; |
84 | | - |
85 | | -Example 4 |
86 | | - |
87 | | -// Insert into the database |
| 38 | +$setting = new Config('****', [$dsn_path_user, $password, $database, $or, $other_settings]); |
88 | 39 |
|
89 | | -```php |
90 | | -$db->query("INSERT INTO users (id, name, email) VALUES (NULL,'justin',' [email protected]')"); |
| 40 | +$db = new ez_****($settings); |
91 | 41 | ``` |
92 | | - |
93 | | -Example 5 |
94 | | - |
95 | | -// Update the database |
96 | | -$db->query("UPDATE users SET name = 'Justin' WHERE id = 2)"); |
97 | | - |
98 | | -Example 6 |
99 | | - |
100 | | -// Display last query and all associated results |
101 | | -$db->debug(); |
102 | | - |
103 | | -Example 7 |
104 | | - |
105 | | -// Display the structure and contents of any result(s) .. or any variable |
106 | | -$results = $db->get_results("SELECT name, email FROM users"); |
107 | | -$db->vardump($results); |
108 | | - |
109 | | -Example 8 |
110 | | - |
111 | | -// Get 'one column' (based on column index) and print it out.. |
112 | | -$names = $db->get_col("SELECT name,email FROM users",0) |
113 | | -foreach ( $names as $name ) |
114 | | -{ |
115 | | - echo $name; |
116 | | -} |
117 | | - |
118 | | -Example 9 |
119 | | - |
120 | | -// Same as above ‘but quicker’ |
121 | | -foreach ( $db->get_col("SELECT name,email FROM users",0) as $name ) |
122 | | -{ |
123 | | - echo $name; |
124 | | -} |
125 | | - |
126 | | -Example 10 |
127 | | - |
128 | | -// Map out the full schema of any given database and print it out.. |
129 | | -$db->select("my_database"); |
130 | | -foreach ( $db->get_col("SHOW TABLES",0) as $table_name ) |
131 | | -{ |
132 | | - $db->debug(); |
133 | | - $db->get_results("DESC $table_name"); |
134 | | -} |
135 | | -$db->debug(); |
136 | 42 |
|
| 43 | +**For** **[Authors/Contributors](https://github.com/ezsql/ezsql/CONTRIBUTORS.md)** |
0 commit comments