Commit 407ef864 authored by Zachary Queal's avatar Zachary Queal

Updated syntax, spelling

Added proper Markdown markup, fixed a spelling error or two. Removed unnecessary white space in PHP syntax.
parent 5f443c88
To utilize this class, first import Mysqldbi.php into your project, and require it. To utilize this class, first import Mysqldbi.php into your project, and require it.
<pre> ```php
<code>
require_once('Mysqlidb.php'); require_once('Mysqlidb.php');
</code> ```
</pre>
After that, create a new instance of the class. After that, create a new instance of the class.
<pre> ```php
<code>
$db = new Mysqlidb('host', 'username', 'password', 'databaseName'); $db = new Mysqlidb('host', 'username', 'password', 'databaseName');
</code> ```
</pre>
Next, prepare your data, and call the necessary methods. Next, prepare your data, and call the necessary methods.
<h3> Insert Query </h3> ### Insert Query
<pre>
<code>
```php
$insertData = array( $insertData = array(
'title' => 'Inserted title', 'title' => 'Inserted title',
'body' => 'Inserted body' 'body' => 'Inserted body'
); );
if ( $db->insert('posts', $insertData) ) echo 'success!'; if($db->insert('posts', $insertData)) echo 'success!';
```
</code> ### Select Query
</pre>
<h3> Select Query </h3> ```php
<pre>
<code>
$results = $db->get('tableName', 'numberOfRows-optional'); $results = $db->get('tableName', 'numberOfRows-optional');
print_r($results); // contains array of returned rows print_r($results); // contains array of returned rows
</code> ```
</pre>
<h3> Update Query </h3> ### Update Query
<pre> ```php
<code>
$updateData = array( $updateData = array(
'fieldOne' => 'fieldValue', 'fieldOne' => 'fieldValue',
'fieldTwo' => 'fieldValue' 'fieldTwo' => 'fieldValue'
); );
$db->where('id', int); $db->where('id', int);
$results = $db->update('tableName', $updateData); $results = $db->update('tableName', $updateData);
</code> ```
</pre>
<h3> Delete Query </h3> ### Delete Query
<pre> ```php
<code>
$db->where('id', int); $db->where('id', int);
if ( $db->delete('posts') ) echo 'successfully deleted'; if($db->delete('posts')) echo 'successfully deleted';
</code> ```
</pre>
<h3> Generic Query Method </h3> ### Generic Query Method
<pre> ```php
<code>
$results = $db->query('SELECT * from posts'); $results = $db->query('SELECT * from posts');
print_r($results); // contains array of returned rows print_r($results); // contains array of returned rows
</code> ```
</pre>
<h3> Raw Query Method </h3> ### Raw Query Method
<pre> ```php
<code>
$params = array(3, 'My Title'); $params = array(3, 'My Title');
$resutls = $db->rawQuery("SELECT id, title, body FROM posts WHERE id = ? AND tile = ?", $params); $resutls = $db->rawQuery("SELECT id, title, body FROM posts WHERE id = ? AND tile = ?", $params);
print_r($results); // contains array of returned rows print_r($results); // contains array of returned rows
...@@ -81,31 +65,26 @@ print_r($results); // contains array of returned rows ...@@ -81,31 +65,26 @@ print_r($results); // contains array of returned rows
// will handle any SQL query // will handle any SQL query
$params = array(10, 1, 10, 11, 2, 10); $params = array(10, 1, 10, 11, 2, 10);
$resutls = $db->rawQuery(" $resutls = $db->rawQuery("(SELECT a FROM t1 WHERE a = ? AND B = ? ORDER BY a LIMIT ?) UNION(SELECT a FROM t2 WHERE a = ? AND B = ? ORDER BY a LIMIT ?)", $params);
(SELECT a FROM t1 WHERE a = ? AND B = ? ORDER BY a LIMIT ?)
UNION
(SELECT a FROM t2 WHERE a = ? AND B = ? ORDER BY a LIMIT ?)
", $params);
print_r($results); // contains array of returned rows print_r($results); // contains array of returned rows
</code> ```
</pre>
### Where Method
This method allows you to specify the parameters of the query.
<h3> Where Method </h3> ```php
<p>This method allows you to specify the parameters of the query.</p>
<pre>
<code>
$db->where('id', int); $db->where('id', int);
$db->where('title', string); $db->where('title', string);
$results = $db->get('tableName'); $results = $db->get('tableName');
print_r($results); // contains array of returned rows print_r($results); // contains array of returned rows
```
Optionally you can use method chaining to call where multiple times without referencing your object over an over:
Optionally you can use method chaining to call where multiple times without referancing your object over an over: ```php
$results = $db $results = $db
->where('id', 1) ->where('id', 1)
->where('title', 'MyTitle') ->where('title', 'MyTitle')
->get('tableName'); ->get('tableName');
```
</code>
</pre>
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