Page 1 of 1

Using PHP to truncate a table (empty or drop it)

Posted: Tue Dec 28, 2004 5:54 pm
by robster
I know it sounds silly, but I can't find the code to do this on Google or on php.net.

I need to say basically: 'Empty table X' I don't even need a while clause or anything. :)

Sorry to directly ask for code, but i have searched and searched and have just had enough so I thought I'd just come here and ask :)

Thanks a tonne!

Rob

Posted: Tue Dec 28, 2004 6:06 pm
by feyd
[mysql_man]truncate[/mysql_man] and [mysql_man]drop[/mysql_man] ... :?

Posted: Tue Dec 28, 2004 6:16 pm
by robster
Thank you yes, I did see that :)

It basically says (in my case) to do this:

TRUNCATE TABLE 'artwork_info_tmp'

The problem being I really don't know how to convert that MYSQL code into PHP ready code. I'm presuming it gets called from an UPDATE function or similar?

Thanks again, I really appreciate it :)

Rob

Posted: Tue Dec 28, 2004 6:17 pm
by timvw
just do it like you perform your other queries, usually

$query = "select * from bar";
$query2 = "truncate bar";

$result = [php_man]mysql_query[/php_man]($query);

Posted: Tue Dec 28, 2004 6:31 pm
by robster
worked a charm, this was the final code :

$query = "select * from artwork_info_tmp";
$query2 = "truncate artwork_info_tmp";
$result = mysql_query($query);
$result = mysql_query($query2);
mysql_free_result($result);

Posted: Tue Dec 28, 2004 11:08 pm
by magicrobotmonkey
you dont need the select query as you obviously dont do anything with it as you immediately write it over

Code: Select all

<?php
 	
$query = "truncate artwork_info_tmp";
$result = mysql_query($query);
mysql_free_result($result);
?>