MySQL and PHP DROP TABLE based on value in table -


i have database entries inserted tables timestamp (an int php's time() not sql timestamp). want make query drop tables greatest timestamp less expiry time (some time time query executed). right have

$q = mysqli_query(..., "show tables 'prefix%'"); if($q===false) die(mysqli_error(...)); for($row in mysqli_fetch_array($q)){     $slice = array_slice($row, 0, 1);     $tbl = array_shift($slice);     mysqli_query(..., "drop table `$tbl` ((select greatest (select `time` `$tbl`)) <= $expiry_time)"); } 

this gives sql syntax error.

what correct way achieve this? also, possible eliminate php logic , loop through each table , drop if necessary in sql?

the approach you've tried not work - you're mixing data definition statements data manipulation statements.

you in stored procedure in mysql, haven't tried it.

so you're faced choice: in mysql via stored procedure (which, mind, kind of hides implementation) or in php (where code more accessible , understandable).

note that, in either event, you'll need lock tables prevent table disappearing between time when query (to find timestamp value) , time when drop it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -