您的位置:首页 > 编程语言 > PHP开发

PHP中如何连接Mysql以及读取数据

2013-02-27 17:48 696 查看
// open the connection

$conn = mysql_connect(host名, 用户名, 密码);

// pick the database to use

mysql_query("SET NAMES UTF8");

mysql_select_db(数据库名,$conn);

// create the SQL statement

$sql = "SELECT * FROM 表名";

// execute the SQL statement

$result = mysql_query($sql, $conn) or die(mysql_error());

//go through each row in the result set and display data

while ($newArray = mysql_fetch_array($result)) {

// give a name to the fields,这个只是例子

$tid = $newArray['tid'];

//以下就是各自的应用编程

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: