<?php
error_reporting(E_DEPRECATED);
//定义常量
define ("DB_HOST","localhost");
define ("DB_USER","root");
define ("DB_PASS","");
define ("DB_DATABASENAME","jia");
define ("DB_TABLENAME","students");
//数据库表的列名
$dbcolarry = array (
"id",
"stuname",
"sex",
"age",
"tel"
);
//php里面的变量可以不用类型
$link = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die("connection error".mysql_error());
echo "$link";
$flag=mysql_select_db(DB_DATABASENAME,$link);
mysql_query ( "set names gbk" );//设置编码方式
if($flag){
echo "数据库连接成功!";
}
//$sql = "select * from students";
$result = mysql_query ( "select * from students",$link);
echo $result;
do{
$info = mysql_fetch_array ($result);
if ($info){
echo $info['stuname']; //注意区分大小写以及表的名称,编码是否统一是GBK
}
} while ($info)
}
?>
共 0 条评论