Copy Code code as follows:
$CN = mysql_connect (' 127.0.0.1 ', ' root ', ' root ') or Die (' Database connect fail ');
mysql_select_db (' Test ', $CN);
mysql_query ("Set names ' GBK '");
/*
Create a database tutorial
CREATE DATABASE ' test ';
Create data Table Test1
CREATE TABLE ' test '. ' Test1 ' (
' ID ' INT (4) Not NULL auto_increment,
' title ' VARCHAR NULL DEFAULT ' 0 ',
' Litpic ' VARCHAR (MB) NULL DEFAULT ' 0 ',
PRIMARY KEY (' id ')
) ENGINE = MYISAM
*/
$sql = "SELECT * from Test1";
$query = mysql_query ($sql) or Die ($sql);
if (mysql_num_rows ($query))
{
while ($rs = Mysql_fetch_array ($query))
{
$sql = "Delete from test1 where id=". $rs [' id '];
if (mysql_query ($sql))
{
if (Defile ($rs [' litpic '])
{
echo ' Delete picture file failed ';
}
Else
{
Echo ' record deleted successfully and deleted the corresponding picture or file ';
}
}
Else
{
Echo ' record does not save delete data and picture failed ';
}
}
}
Else
{
Echo ' no record ';
}
/*
@pare return
# $url String
deleting files
*/
function Delfile ($url)
{
if (file_exists ($url) && is_file ($url))
{
if (unlink ($url))
{
return true;
}
Else
{
return false;
}
}
Else
{
return false;
}
}