Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PHP PDO Mysql Multiple Query Bug Debugger. Bug Page:
$myConn = new PDO(
$multiSqlStatement = '
INSERT INTO users (username) VALUES (:username);
INSERT INTO groups (name, type) VALUES (:group_name, :group_type);
INSERT INTO logs (entry) VALUES (NOW());
$bindVariables = array(
':group_type' => 'this_type',
':username' => 'my_username',
':group_name' => 'Other'
$tempSql = preg_replace('/[\n\r\s]+/', ' ', $multiSqlStatement);
$tempSqlParts = explode(';', $tempSql);
foreach ($tempSqlParts as $tempSqlPart) {
$tempSqlPart = trim($tempSqlPart);
if (!empty($tempSqlPart)) {
$tempBindVars = (0 < preg_match_all('/\:[a-z0-9_]+/i', $tempSqlPart, $matches))
? array_intersect_key($bindVariables, array_flip($matches[0]))
: array();
$tempStatement = $myConn->prepareStatement($tempSqlPart);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.