PHP操作mysql

来源:互联网 发布:男士搭配软件 编辑:程序博客网 时间:2024/06/07 06:37

案例:

header(‘Content-type:text/html;charset=uft-8’);

**// 七贱下天山**第一贱 连接mysql服务器mysql_connect('127.0.0.1', 'root', '123') or die('连接数据库失败'); 第二贱 选择数据库mysql_query('use itcast');// mysql_select_db('itcast');第三贱 设置字符集mysql_query('set names utf8');第四贱 构建sql语句$sql = "select * from student";第五贱 发送sql语句$res = mysql_query($sql);// 如果sql语句错误,终止并输出错误信息if(!$res){    exit(mysql_error());}第六贱 处理结果集// 增删改// 查$row = mysql_fetch_row($res);  //枚举数组mysql_fetch_assoc($res);//关联数组mysql_fetch_array($res, MYSQL_ASSOC); //关联数组 等价于 mysql_fetch_assoc($res);mysql_fetch_array($res, MYSQL_BOTH);  //既有关联数组,也有索引数组mysql_data_seek($res, 10); // 移动资源的指针// 第七贱 万贱归宗mysql_close();// php版本高

?>

0 0