In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章主要介绍"php可以删除记录图片吗",在日常操作中,相信很多人在php可以删除记录图片吗问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"php可以删除记录图片吗"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
php能删除记录图片,其删除方法是:1、创建PHP文件并连接数据库;2、通过"Delete from test1 where id=".$rs['id'];"等语句删除记录图片即可。
本文操作环境:windows7系统、PHP7.1版、DELL G3电脑
php能删除记录图片吗?
php 删除记录同时删除图片文件的实现代码:
$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; } }到此,关于"php可以删除记录图片吗"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.