Skip to content

Commit 77cc8fc

Browse files
authored
Update readme.md
1 parent 415a91f commit 77cc8fc

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

readme.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
22
<hr>
33
### Table of Contents
4+
(All _italic_ categories has been implemented by me.)
5+
46
**[Initialization](#initialization)**
57
**[Objects mapping](#objects-mapping)**
68
**[Insert Query](#insert-query)**
79
**[Update Query](#update-query)**
810
**[Select Query](#select-query)**
911
**[Delete Query](#delete-query)**
12+
**>> _[Insert Data](#insert-data)_**
13+
**>> _[Insert XML](#insert-xml)_**
1014
**[Running raw SQL queries](#running-raw-sql-queries)**
1115
**[Query Keywords](#query-keywords)**
1216
**[Where Conditions](#where--having-methods)**
@@ -20,6 +24,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
2024
**[Helper Methods](#helper-methods)**
2125
**[Transaction Helpers](#transaction-helpers)**
2226
**[Error Helpers](#error-helpers)**
27+
**>> _[Table Locking](#table-locking)_**
2328

2429
## Support Me
2530

@@ -212,6 +217,55 @@ foreach ($logins as $login)
212217
echo $login;
213218
```
214219

220+
###Insert Data
221+
You can also load .CSV or .XML data into a specific table.
222+
To insert .csv data, use the following syntax:
223+
```php
224+
$path_to_file = "/home/john/file.csv";
225+
$db->loadData("users", $path_to_file);
226+
```
227+
This will load a .csv file called **file.csv** in the folder **/home/john/** (john's home directory.)
228+
You can also attach an optional array of options.
229+
Valid options are:
230+
231+
```php
232+
Array(
233+
"fieldChar" => ';', // Char which separates the data
234+
"lineChar" => '\r\n', // Char which separates the lines
235+
"linesToIgnore" => 1 // Amount of lines to ignore at the beginning of the import
236+
);
237+
```
238+
239+
Attach them using
240+
```php
241+
$options = Array("fieldChar" => ';', "lineChar" => '\r\n', "linesToIgnore" => 1);
242+
$db->loadData("users", "/home/john/file.csv", $options);
243+
```
244+
245+
###Insert XML
246+
To load XML data into a table, you can use the method **loadXML**.
247+
The syntax is smillar to the loadData syntax.
248+
```php
249+
$path_to_file = "/home/john/file.xml";
250+
$db->loadXML("users", $path_to_file);
251+
```
252+
253+
You can also add optional parameters.
254+
Valid parameters:
255+
```php
256+
Array(
257+
"linesToIgnore" => 0, // Amount of lines / rows to ignore at the beginning of the import
258+
"rowTag" => "<user>" // The tag which marks the beginning of an entry
259+
)
260+
```
261+
262+
Usage:
263+
```php
264+
$options = Array("linesToIgnore" => 0, "rowTag" => "<user>"):
265+
$path_to_file = "/home/john/file.xml";
266+
$db->loadXML("users", $path_to_file, $options);
267+
```
268+
215269
###Pagination
216270
Use paginate() instead of get() to fetch paginated result
217271
```php
@@ -630,6 +684,7 @@ if (!$db->insert ('myTable', $insertData)) {
630684
}
631685
```
632686

687+
633688
### Error helpers
634689
After you executed a query you have options to check if there was an error. You can get the MySQL error string or the error code for the last executed query.
635690
```php
@@ -668,3 +723,27 @@ print_r ($db->trace);
668723
)
669724
670725
```
726+
727+
##Table Locking
728+
To lock tables, you can use the **lock** method together with **setLockMethod**.
729+
The following example will lock the table **users** for **write** access.
730+
```php
731+
$db->setLockMethod("WRITE")->lock("users");
732+
```
733+
734+
Calling another **->lock()** will remove the first lock.
735+
You can also use
736+
```php
737+
$db->unlock();
738+
```
739+
to unlock the previous locked tables.
740+
To lock multiple tables, you can use an array.
741+
Example:
742+
```php
743+
$db->setLockMethod("READ")->lock(array("users", "log"));
744+
```
745+
This will lock the tables **users** and **log** for **READ** access only.
746+
Make sure you use **unlock()* afterwards or your tables will remain locked!
747+
748+
749+
Last edited by Noneatme on June 28.

0 commit comments

Comments
 (0)