Skip to content

Commit e30c240

Browse files
committed
cleanup README, add note about $logfile
1 parent 13f249f commit e30c240

File tree

1 file changed

+83
-49
lines changed

1 file changed

+83
-49
lines changed

README.md

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,85 @@ When you're ready to get started, see the [Quick Start Guide](http://www.meekro.
1515
### Manual Setup
1616
Include the `db.class.php` file into your project and set it up like this:
1717

18-
require_once 'db.class.php';
19-
DB::$user = 'my_database_user';
20-
DB::$password = 'my_database_password';
21-
DB::$dbName = 'my_database_name';
18+
```php
19+
require_once 'db.class.php';
20+
DB::$user = 'my_database_user';
21+
DB::$password = 'my_database_password';
22+
DB::$dbName = 'my_database_name';
23+
```
2224

2325
### Composer
2426
Add this to your `composer.json`
2527

26-
{
27-
"require": {
28-
"sergeytsalkov/meekrodb": "*"
29-
}
30-
}
28+
```json
29+
{
30+
"require": {
31+
"sergeytsalkov/meekrodb": "*"
32+
}
33+
}
34+
```
3135

3236
Code Examples
3337
========
3438
### Grab some rows from the database and print out a field from each row.
3539

36-
$accounts = DB::query("SELECT * FROM accounts WHERE type = %s AND age > %i", $type, 15);
37-
foreach ($accounts as $account) {
38-
echo $account['username'] . "\n";
39-
}
40+
```php
41+
$accounts = DB::query("SELECT * FROM accounts WHERE type = %s AND age > %i", $type, 15);
42+
foreach ($accounts as $account) {
43+
echo $account['username'] . "\n";
44+
}
45+
```
46+
47+
4048

4149
### Insert a new row.
4250

43-
DB::insert('mytable', array(
44-
'name' => $name,
45-
'rank' => $rank,
46-
'location' => $location,
47-
'age' => $age,
48-
'intelligence' => $intelligence
49-
));
51+
```php
52+
DB::insert('mytable', array(
53+
'name' => $name,
54+
'rank' => $rank,
55+
'location' => $location,
56+
'age' => $age,
57+
'intelligence' => $intelligence
58+
));
59+
```
5060

5161
### Grab one row or field
5262

53-
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
54-
$number_accounts = DB::queryFirstField("SELECT COUNT(*) FROM accounts");
63+
```php
64+
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
65+
$number_accounts = DB::queryFirstField("SELECT COUNT(*) FROM accounts");
66+
```
5567

5668
### Use a list in a query
57-
DB::query("SELECT * FROM tbl WHERE name IN %ls AND age NOT IN %li", array('John', 'Bob'), array(12, 15));
69+
```php
70+
DB::query("SELECT * FROM tbl WHERE name IN %ls AND age NOT IN %li", array('John', 'Bob'), array(12, 15));
71+
```
5872

59-
### Nested Transactions
73+
### Log all queries and errors
74+
```php
75+
// log all queries and errors to file, or ..
76+
DB::$logfile = '/home/username/logfile.txt';
6077

61-
DB::$nested_transactions = true;
62-
DB::startTransaction(); // outer transaction
63-
// .. some queries..
64-
$depth = DB::startTransaction(); // inner transaction
65-
echo $depth . 'transactions are currently active'; // 2
66-
67-
// .. some queries..
68-
DB::commit(); // commit inner transaction
69-
// .. some queries..
70-
DB::commit(); // commit outer transaction
78+
// log all queries and errors to screen
79+
DB::$logfile = fopen('php://output', 'w');
80+
```
81+
82+
### Nested Transactions
83+
```php
84+
DB::$nested_transactions = true;
85+
DB::startTransaction(); // outer transaction
86+
// .. some queries..
87+
$depth = DB::startTransaction(); // inner transaction
88+
echo $depth . 'transactions are currently active'; // 2
89+
90+
// .. some queries..
91+
DB::commit(); // commit inner transaction
92+
// .. some queries..
93+
DB::commit(); // commit outer transaction
94+
```
7195

72-
### Lots More - See: http://www.meekro.com/docs.php
96+
### Lots More - See: http://meekro.com/docs
7397

7498

7599
How is MeekroDB better than PDO?
@@ -84,41 +108,51 @@ MeekroDB works. Still, if you need database objects, MeekroDB can do that too.
84108
The code below escapes your parameters for safety, runs the query, and grabs
85109
the first row of results. Try doing that in one line with PDO.
86110

87-
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
111+
```php
112+
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
113+
```
88114

89115
Or how about just one field?
90116

91-
$created_at = DB::queryFirstField("SELECT created_at FROM accounts WHERE username=%s", 'Joe');
117+
```php
118+
$created_at = DB::queryFirstField("SELECT created_at FROM accounts WHERE username=%s", 'Joe');
119+
```
92120

93121
### Work with list parameters easily
94122
Using MySQL's IN keyword should not be hard. MeekroDB smooths out the syntax for you,
95123
PDO does not.
96124

97-
$accounts = DB::query("SELECT * FROM accounts WHERE username IN %ls", array('Joe', 'Frank'));
125+
```php
126+
$accounts = DB::query("SELECT * FROM accounts WHERE username IN %ls", array('Joe', 'Frank'));
127+
```
98128

99129

100130
### Simple inserts
101131
Using MySQL's INSERT should not be more complicated than passing in an
102132
associative array. MeekroDB also simplifies many related commands, including
103133
the useful and bizarre INSERT .. ON DUPLICATE UPDATE command. PDO does none of this.
104134

105-
DB::insert('accounts', array('username' => 'John', 'password' => 'whatever'));
135+
```php
136+
DB::insert('accounts', array('username' => 'John', 'password' => 'whatever'));
137+
```
106138

107139
### Nested transactions
108140
MySQL's SAVEPOINT commands lets you create nested transactions, but only
109141
if you keep track of SAVEPOINT ids yourself. MeekroDB does this for you,
110142
so you can have nested transactions with no complexity or learning curve.
111143

112-
DB::$nested_transactions = true;
113-
DB::startTransaction(); // outer transaction
114-
// .. some queries..
115-
$depth = DB::startTransaction(); // inner transaction
116-
echo $depth . 'transactions are currently active'; // 2
117-
118-
// .. some queries..
119-
DB::commit(); // commit inner transaction
120-
// .. some queries..
121-
DB::commit(); // commit outer transaction
144+
```php
145+
DB::$nested_transactions = true;
146+
DB::startTransaction(); // outer transaction
147+
// .. some queries..
148+
$depth = DB::startTransaction(); // inner transaction
149+
echo $depth . 'transactions are currently active'; // 2
150+
151+
// .. some queries..
152+
DB::commit(); // commit inner transaction
153+
// .. some queries..
154+
DB::commit(); // commit outer transaction
155+
```
122156

123157
### Flexible debug logging and error handling
124158
You can log all queries (and any errors they produce) to a file for debugging purposes. You can also add hooks that let you run your own functions at any point in the query handling process.

0 commit comments

Comments
 (0)