Home >php教程 >php手册 >mysql数据更新与插入保存

mysql数据更新与插入保存

WBOY
WBOYOriginal
2016-05-25 16:46:171232browse

$hostname="localhost";         //定义连接到的mysql服务器名 
$username="root";          //定义用于连接的用户名 
$password="";           //定义用于连接的密码 
$link=mysql_connect($hostname,$username,$password);   //连接到mysql服务器 
mysql_select_db("test",$link);        //选择数据库 
//定义sql语句 
$sql_str="update friends set name='andy' where id=1"; 
mysql_query($sql_str) or die("出现错误!");         //执行sql查询 
echo mysql_info($link); 
//定义sql语句,执行修改操作 
$sql_str="insert into friends(name,sex,birthday,address)values('陈靖仇','男','593-08-23','天之痕')"; 
mysql_query($sql_str) or die("出现错误!");     //执行sql查询 
printf("最后一次插入操作的id值为:%dn",mysql_insert_id());   //返回insert影响的id值


教程地址:

欢迎转载!但请带上文章地址^^

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn