Skip to content

Commit

Permalink
PDO-debugger is now a static method inside a helper class, not a glob…
Browse files Browse the repository at this point in the history
…al function anymore
  • Loading branch information
panique committed Nov 9, 2014
1 parent e7f7299 commit e41338f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ are using extremely outdated MySQL versions).

## Goodies

MINI comes with a little [PDO debugger tool](https://github.com/panique/pdo-debug), trying to emulate your PDO-SQL
statements. It's extremely easy to use:
MINI comes with a little customized [PDO debugger tool](https://github.com/panique/pdo-debug) (find the code in
application/libs/helper.php), trying to emulate your PDO-SQL statements. It's extremely easy to use:

```php
$sql = "SELECT id, artist, track, link FROM song WHERE id = :song_id LIMIT 1";
$query = $this->db->prepare($sql);
$parameters = array(':song_id' => $song_id);

echo debugPDO($sql, $parameters);
echo Helper::debugPDO($sql, $parameters);

$query->execute($parameters);
```
Expand Down
15 changes: 7 additions & 8 deletions application/libs/pdo-debug.php → application/libs/helper.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

// if it does not exist, add the function debugPDO to PHP
// for more info about this function, see https://github.com/panique/pdo-debug
if (!function_exists('debugPDO')) {

class Helper
{
/**
* debugPDO
*
* Shows the SQL query constructed by PDO. The magic behind: A simple function that combines your parameters and
* the raw query. Not perfect, but does the job.
* Shows the emulated SQL query in a PDO statement. What it does is just extremely simple, but powerful:
* It combines the raw query and the placeholders. For sure not really perfect (as PDO is more complex than just
* combining raw query and arguments), but it does the job.
*
* @author Panique <https://github.com/panique/pdo-debug>
* @author Panique
* @param string $raw_sql
* @param array $parameters
* @return string
*/
function debugPDO($raw_sql, $parameters) {
static public function debugPDO($raw_sql, $parameters) {

$keys = array();
$values = $parameters;
Expand Down
8 changes: 4 additions & 4 deletions application/model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function addSong($artist, $track, $link)
$parameters = array(':artist' => $artist, ':track' => $track, ':link' => $link);

// useful for debugging: you can see the SQL behind above construction by using:
// echo '[ PDO DEBUG ]: ' . debugPDO($sql, $parameters); exit();
// echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();

$query->execute($parameters);
}
Expand All @@ -66,7 +66,7 @@ public function deleteSong($song_id)
$parameters = array(':song_id' => $song_id);

// useful for debugging: you can see the SQL behind above construction by using:
// echo '[ PDO DEBUG ]: ' . debugPDO($sql, $parameters); exit();
// echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();

$query->execute($parameters);
}
Expand All @@ -81,7 +81,7 @@ public function getSong($song_id)
$parameters = array(':song_id' => $song_id);

// useful for debugging: you can see the SQL behind above construction by using:
// echo '[ PDO DEBUG ]: ' . debugPDO($sql, $parameters); exit();
// echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();

$query->execute($parameters);

Expand All @@ -108,7 +108,7 @@ public function updateSong($artist, $track, $link, $song_id)
$parameters = array(':artist' => $artist, ':track' => $track, ':link' => $link, ':song_id' => $song_id);

// useful for debugging: you can see the SQL behind above construction by using:
// echo '[ PDO DEBUG ]: ' . debugPDO($sql, $parameters); exit();
// echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();

$query->execute($parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// FOR DEVELOPMENT: this loads PDO-debug, a simple function that shows the SQL query (when using PDO).
// If you want to load pdoDebug via Composer, then have a look here: https://github.com/panique/pdo-debug
require APP . '/libs/pdo-debug.php';
require APP . '/libs/helper.php';

// load application class
require APP . '/core/application.php';
Expand Down

0 comments on commit e41338f

Please sign in to comment.