PHP连接MySQL数据库的mysql

磊落不羁 by:磊落不羁 分类:基本语法 时间:4年前 阅读:128 评论:0
<?php
$mysql_conf = array(
    "host"    => "127.0.0.1:3306", 
    "db"      => "test", 
    "db_user" => "root", 
    "db_pwd"  => "root", 
    );
$mysql_conn = @mysql_connect($mysql_conf["host"], $mysql_conf["db_user"], $mysql_conf["db_pwd"]);
if (!$mysql_conn) {
    die("could not connect to the database:
" . mysql_error());//诊断连接错误
}
mysql_query("set names "utf8"");//编码转化
$select_db = mysql_select_db($mysql_conf["db"]);
if (!$select_db) {
    die("could not connect to the db:
" .  mysql_error());
}
$sql = "select * from user;";
$res = mysql_query($sql);
if (!$res) {
    die("could get the res:
" . mysql_error());
}

while ($row = mysql_fetch_assoc($res)) {
    print_r($row);
}

mysql_close($mysql_conn);
?>


非特殊说明,本文版权归原作者所有,转载请注明出处

本文地址:http://php.liulei.com.cn/?type=acticle&id=3

评论列表

发表评论

  • 昵称(必填)
  • 邮箱
  • 网址

TOP