Skip to content

Instantly share code, notes, and snippets.

@LaffinToo
Last active August 29, 2015 14:00
Show Gist options
  • Save LaffinToo/7281fcabc11da723e898 to your computer and use it in GitHub Desktop.
Save LaffinToo/7281fcabc11da723e898 to your computer and use it in GitHub Desktop.
account_delete function - #MySQL #Multiple row #deletion
<?php
function account_delete($userid)
{
$references=array(
"id" => array("users"), // Do Not move this line
"userid" => array(
"blackjack","blocks","bookmarks"
),
"friendid" => array(
"friends"
),
);
$ctr=1;
foreach($references as $field=>$tablelist)
{
foreach($tablelist as $table)
{
$tables[]=$tc="t{$ctr}";
$joins[]=($ctr==1)?"users as {$tc}":"INNER JOIN {$table} as {$tc} on t0.id={$tc}.{$field}";
$ctr++;
}
}
return 'DELETE '. implode(', ',$tables) . " FROM " . implode(' ',$joins) . " WHERE t0.id='{$userid}';";
}
echo account_delete(256). PHP_EOL;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment