Commit 77cc8fc7 authored by Noneatme's avatar Noneatme Committed by GitHub

Update readme.md

parent 415a91ff
MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
<hr> <hr>
### Table of Contents ### Table of Contents
(All _italic_ categories has been implemented by me.)
**[Initialization](#initialization)** **[Initialization](#initialization)**
**[Objects mapping](#objects-mapping)** **[Objects mapping](#objects-mapping)**
**[Insert Query](#insert-query)** **[Insert Query](#insert-query)**
**[Update Query](#update-query)** **[Update Query](#update-query)**
**[Select Query](#select-query)** **[Select Query](#select-query)**
**[Delete Query](#delete-query)** **[Delete Query](#delete-query)**
**>> _[Insert Data](#insert-data)_**
**>> _[Insert XML](#insert-xml)_**
**[Running raw SQL queries](#running-raw-sql-queries)** **[Running raw SQL queries](#running-raw-sql-queries)**
**[Query Keywords](#query-keywords)** **[Query Keywords](#query-keywords)**
**[Where Conditions](#where--having-methods)** **[Where Conditions](#where--having-methods)**
...@@ -20,6 +24,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements ...@@ -20,6 +24,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
**[Helper Methods](#helper-methods)** **[Helper Methods](#helper-methods)**
**[Transaction Helpers](#transaction-helpers)** **[Transaction Helpers](#transaction-helpers)**
**[Error Helpers](#error-helpers)** **[Error Helpers](#error-helpers)**
**>> _[Table Locking](#table-locking)_**
## Support Me ## Support Me
...@@ -212,6 +217,55 @@ foreach ($logins as $login) ...@@ -212,6 +217,55 @@ foreach ($logins as $login)
echo $login; echo $login;
``` ```
###Insert Data
You can also load .CSV or .XML data into a specific table.
To insert .csv data, use the following syntax:
```php
$path_to_file = "/home/john/file.csv";
$db->loadData("users", $path_to_file);
```
This will load a .csv file called **file.csv** in the folder **/home/john/** (john's home directory.)
You can also attach an optional array of options.
Valid options are:
```php
Array(
"fieldChar" => ';', // Char which separates the data
"lineChar" => '\r\n', // Char which separates the lines
"linesToIgnore" => 1 // Amount of lines to ignore at the beginning of the import
);
```
Attach them using
```php
$options = Array("fieldChar" => ';', "lineChar" => '\r\n', "linesToIgnore" => 1);
$db->loadData("users", "/home/john/file.csv", $options);
```
###Insert XML
To load XML data into a table, you can use the method **loadXML**.
The syntax is smillar to the loadData syntax.
```php
$path_to_file = "/home/john/file.xml";
$db->loadXML("users", $path_to_file);
```
You can also add optional parameters.
Valid parameters:
```php
Array(
"linesToIgnore" => 0, // Amount of lines / rows to ignore at the beginning of the import
"rowTag" => "<user>" // The tag which marks the beginning of an entry
)
```
Usage:
```php
$options = Array("linesToIgnore" => 0, "rowTag" => "<user>"):
$path_to_file = "/home/john/file.xml";
$db->loadXML("users", $path_to_file, $options);
```
###Pagination ###Pagination
Use paginate() instead of get() to fetch paginated result Use paginate() instead of get() to fetch paginated result
```php ```php
...@@ -630,6 +684,7 @@ if (!$db->insert ('myTable', $insertData)) { ...@@ -630,6 +684,7 @@ if (!$db->insert ('myTable', $insertData)) {
} }
``` ```
### Error helpers ### Error helpers
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. 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.
```php ```php
...@@ -668,3 +723,27 @@ print_r ($db->trace); ...@@ -668,3 +723,27 @@ print_r ($db->trace);
) )
``` ```
##Table Locking
To lock tables, you can use the **lock** method together with **setLockMethod**.
The following example will lock the table **users** for **write** access.
```php
$db->setLockMethod("WRITE")->lock("users");
```
Calling another **->lock()** will remove the first lock.
You can also use
```php
$db->unlock();
```
to unlock the previous locked tables.
To lock multiple tables, you can use an array.
Example:
```php
$db->setLockMethod("READ")->lock(array("users", "log"));
```
This will lock the tables **users** and **log** for **READ** access only.
Make sure you use **unlock()* afterwards or your tables will remain locked!
Last edited by Noneatme on June 28.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment