- A+
所属分类:Mysql
<?php function foo(){ $host = 'localhost'; $database = 'test'; $username = 'root'; $password = 'root'; $connection = mysqli_connect($host, $username, $password);//连接到数据库 if (!$connection) { die("could not connect to the database.\n" . mysqli_error());//诊断连接错误 } $selectedDb = mysqli_select_db($connection,$database);//选择数据库 if (!$selectedDb) { die("could not to the database\n" . mysqli_error()); } $query = "SELECT count(id) FROM wp_posts where DATEDIFF(CURRENT_DATE,post_date_gmt)<6 AND post_content like '%<li></li><li></li>%'";//构建查询语句 $result = mysqli_query($connection,$query);//执行查询 $res = mysqli_fetch_row($result)[0]; echo "<br/>[+]检索条数:".strval($res)."<br/>"; mysqli_close($connection); if (!$result) { die("could not to the database\n" . mysqli_error()); } if ($res==0){ echo '[-]Changed Over<br/>'; } else{ echo "[-]Begin To change<br/>"; $connection1 = mysqli_connect($host, $username, $password);//连接到数据库 $selectedDb = mysqli_select_db($connection1,$database);//选择数据库 $query1 = "update wp_posts set post_content=replace(post_content,'<li></li><li></li>','<li></li>') where DATEDIFF(CURRENT_DATE,post_date_gmt)<6 AND post_content like '%<li></li><li></li>%'";//构建查询语句 $result1=mysqli_query($connection1,$query1);//执行查询 if($result1){ echo '[-]Update ok<br/>'; } else{ echo '[-]Update fail<br/>'; } //echo $res1; mysqli_close($connection1); foo(); } //return $res; } foo(); ?>
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫