<?php
define("DBSERVER","localhost")
define("USER","root")
define("PASSWORD","your password")
define("DB","dbName")
function connectMySQL()
{
@mysql_pconnect(DBSERVER,USER,PASSWORD) or die("服务器繁忙,请刷新后再尝试建立连接")
@mysql_select_db(DB) or die("数据库正在连接中。。。")
}
connectMySQL()
mysql_query("set names utf8")
?>
然后在需要使用到连接数据库的网页加入:
require("db_conn.php")
//参考这个最基本的吧:<?php
$link = mysql_connect('localhost', 'root', '123456')
mysql_select_db('youdatabase', $link)
$result = mysql_query('SELECT id, title FROM table', $link)
?>
<html>
<head>
<title>文章列表</title>
</head>
<body>
<h1>文章列表</h1>
<ul>
<?php while ($row = mysql_fetch_assoc($result)): ?>
<li>
<a href="/show.php?id=<?php echo $row['id'] ?>">
<?php echo $row['title'] ?>
</a>
</li>
<?php endwhile ?>
</ul>
</body>
</html>
<?php
mysql_close($link)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)