1、连接数据库服务器:
3、执行SQL语句:
- $coon = mysql_connect("服务器","用户名","密码");
2、选择数据库
- mysql_select_db("数据库","数据库连接");
- $rs = mysql_query("sql语句","数据库连接");
4、遍历结果集的方法:
- while($row=mysql_fetch_row($rs){ echo $row[1];} //ROW可以用数组下标获取数据集字段
- while($row=mysql_fethc_array($rs)){echo $row[“username”];} //ROW可以用字段名称和下标数
- while($row = mysql_fetch_row($result))
- {
- echo $row['cid'].'::'.$row[1].'<br>';
- }
- $result = mysql_query($sql);
- while($row = mysql_fetch_array($result))
- {
- echo $row['cid'].'::'.$row[1].'<br>';
- }
- $result = mysql_query($sql);
- while($row = mysql_fetch_object($result))
- {
- echo $row->cid.'::'.$row->title.”<br>”;
- }
- $result = mysql_query($sql);
- while($row = mysql_fetch_assoc($result))
- {
- echo $row['cid'].'::'.$row[1].'<br>';
- }