Last active
February 4, 2019 20:12
-
-
Save luukverhoeven/0fcc3d27ffeaaefcde3a534530f005d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = 'UPDATE mdl_grade_grades SET itemid = ?,userid = ?,rawgrade = ?,rawgrademax = ?,rawgrademin = ?,rawscaleid = ?,usermodified = ?,finalgrade = ?,hidden = ?,locked = ?,locktime = ?,exported = ?,overridden = ?,excluded = ?,timecreated = ?,timemodified = ?,aggregationstatus = ?,aggregationweight = ?,feedback = ?,feedbackformat = ?,information = ?,informationformat = ? WHERE id=?'; | |
// Stackoverflow code. Quick and dirty solution to convert PDO mysql queries. | |
function sql_debug($sql_string, array $params = null) { | |
if (!empty($params)) { | |
$indexed = $params == array_values($params); | |
foreach($params as $k=>$v) { | |
if (is_object($v)) { | |
if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s'); | |
else continue; | |
} | |
elseif (is_string($v)) $v="'$v'"; | |
elseif ($v === null) $v='NULL'; | |
elseif (is_array($v)) $v = implode(',', $v); | |
if ($indexed) { | |
$sql_string = preg_replace('/\?/', $v, $sql_string, 1); | |
} | |
else { | |
if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out | |
$sql_string = str_replace($k,$v,$sql_string); | |
} | |
} | |
} | |
return $sql_string; | |
} | |
echo sql_debug($str ,array ( | |
0 => '1212', | |
1 => '2355', | |
2 => 8.5, | |
3 => 10.0, | |
4 => 0.0, | |
5 => NULL, | |
6 => '2', | |
7 => 7.7999999999999998, | |
8 => '0', | |
9 => '0', | |
10 => '0', | |
11 => '0', | |
12 => 1549308604, | |
13 => '0', | |
14 => '1548412655', | |
15 => 1549308604, | |
16 => 'used', | |
17 => '0.00000', | |
18 => NULL, | |
19 => '0', | |
20 => NULL, | |
21 => '0', | |
22 => '290596', | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PDO moodle query
Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5,rawgrademax = 10,rawgrademin = 0,rawscaleid = NULL,usermodified = '2',finalgra' at line 1
UPDATE mdl_grade_grades SET itemid = ?,userid = ?,rawgrade = ?,rawgrademax = ?,rawgrademin = ?,rawscaleid = ?,usermodified = ?,finalgrade = ?,hidden = ?,locked = ?,locktime = ?,exported = ?,overridden = ?,excluded = ?,timecreated = ?,timemodified = ?,aggregationstatus = ?,aggregationweight = ?,feedback = ?,feedbackformat = ?,information = ?,informationformat = ? WHERE id=?
[array (
0 => '1212',
1 => '2355',
2 => 8.5,
3 => 10.0,
4 => 0.0,
5 => NULL,
6 => '2',
7 => 7.7999999999999998,
8 => '0',
9 => '0',
10 => '0',
11 => '0',
12 => 1549308604,
13 => '0',
14 => '1548412655',
15 => 1549308604,
16 => 'used',
17 => '0.00000',
18 => NULL,
19 => '0',
20 => NULL,
21 => '0',
22 => '290596',
)]
Error code: dmlwriteexception
×