Last active
August 29, 2015 14:00
-
-
Save LaffinToo/7281fcabc11da723e898 to your computer and use it in GitHub Desktop.
account_delete function - #MySQL #Multiple row #deletion
This file contains 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 | |
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