Home > php教程 > php手册 > php连接数据库代码应用分析

php连接数据库代码应用分析

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:53:55
Original
921 people have browsed it

$connect = mysql_connect("127.0.0.1","root","") or die ("链接错误");//开启链接到mysql
$select_db = mysql_select_db("数据库名",$connect);//如果不特别声明连接标示符,则默认上一次打开的链接
//执行SQL语句!
$sql = "SELECT * FROM test"
$query = mysql_query($sql,$connect) or die(mysql_error());

//两种查询函数array/row区别
$row1 = mysql_fetch_row($query);
print_r($row1);//只能保存数组中的标号
$row2 = mysql_fetch_array($query);
print_r($row2);//可以保存数组中的标号,和字段名
//循环输出while输出到空位置
while($row1){
print_r($row1);
}

mysql_query("SET NAMES 'UTF-8'");

//用于计算查询结果的数目
mysql_num_rows($query);
//传回最后一次使用INSERT指令的IP
mysql_insert_id($query);
//取得数据库名
mysql_tablename($query);
//返回错误信息
mysql_error();
//关闭链接
mysql_close();



Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template