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);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值