Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Missing Namespace #76

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions application/Core/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Mini\Core;

class Helper
{
/**
* debugPDO
*
* 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
* @param string $raw_sql
* @param array $parameters
* @return string
*/
static public function debugPDO($raw_sql, $parameters) {

$keys = array();
$values = $parameters;

foreach ($parameters as $key => $value) {

// check if named parameters (':param') or anonymous parameters ('?') are used
if (is_string($key)) {
$keys[] = '/' . $key . '/';
} else {
$keys[] = '/[?]/';
}

// bring parameter into human-readable format
if (is_string($value)) {
$values[$key] = "'" . $value . "'";
} elseif (is_array($value)) {
$values[$key] = implode(',', $value);
} elseif (is_null($value)) {
$values[$key] = 'NULL';
}
}

/*
echo "<br> [DEBUG] Keys:<pre>";
print_r($keys);

echo "\n[DEBUG] Values: ";
print_r($values);
echo "</pre>";
*/

$raw_sql = preg_replace($keys, $values, $raw_sql, 1, $count);

return $raw_sql;
}

}
2 changes: 1 addition & 1 deletion application/Model/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 ]: ' . Helper::debugPDO($sql, $parameters); exit();
// echo '[ PDO DEBUG ]: ' . \Mini\Core\Helper::debugPDO($sql, $parameters); exit();

$query->execute($parameters);
}
Expand Down