php mysql sql 操作数据库

如下以本地项目为例,展示了连接数据库和增、改、查:


//生成连接

$db_connect=mysql_connect('localhost','root','root') or die("Unable to connect to the MySQL!");
mysql_set_charset('utf8');


//数据库
mysql_select_db('mydb');


//执行MySQL语句(查)
$xtSql="select * from system where id=1";
$findXt=mysql_query($xtSql);
$xtRe=mysql_fetch_array($findXt);


//获取时间
$start=$xtRe['xt_wplan_time'];


$table='original';
$time='yc_ok_time';


$S=$start+3600*24*7;
$E=$S+3600*24;


//查询(查)
$wzSql="select * from ".$table." where ".$time.">=$S AND ".$time."<$E order by ".$time." asc";
$findWz=mysql_query($wzSql);
while($row = mysql_fetch_assoc($findWz))
{
//编辑(改)
$uWhere="where id=".$row['uid'];
$newCash=10;
$saveUSql="UPDATE user SET cash=".$newCash." $uWhere";
$saveU=mysql_query($saveUSql);
if($saveU){
//添加(增)
$xxCause="文章返现!";
$xxSql="INSERT INTO `information` (xx_to_user_id,xx_content,xx_time) values(".$row['uid'].",'".$xxCause."',".time().")";
$xxRe=mysql_query($xxSql);
}
}

猜你喜欢

转载自blog.csdn.net/qq_36376116/article/details/79073089