时间:2021-07-01 10:21:17 帮助过:26人阅读
$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 DATABASE `test` ;
创建数据表 test1
CREATE TABLE `test`.`test1` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 40 ) NULL DEFAULT '0',
`litpic` VARCHAR( 100 ) 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 '删除图片文件失败';
}
else
{
echo '记录删除成功,并且删除了记录与相对应的图片或文件';
}
}
else
{
echo '记录不存删除数据与图片失败';
}
}
}
else
{
echo '没有记录';
}
/*
@pare return
#$url string
删除文件
*/
function delfile($url)
{
if( file_exists($url) && is_file( $url ) )
{
if( unlink( $url ) )
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
http://www.bkjia.com/PHPjc/321780.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321780.htmlTechArticle 代码如下:
$cn = mysql_connect('127.0.0.1','root','root') or die('database connect fail'); mysql_select_db('test',$cn); mysql_query("set names 'gbk'"); /* 创建数据...