$server = "localhost:3306";
$username = "root";
$password = "";//123
$dbname = "test";
#echo "
";
$conn = @mysql_connect($server, $username,$password) or die ("XXX");
if($conn) echo("成功");
mysql_select_db($dbname);
#$sqlinsert = "insert into testphp(name,pass) values ('123','123')";
#mysql_query($sqlinsert,$conn);
$sql = "select * from testphp";
$result = @ mysql_query($sql,$conn) or die (mysql_errno());
echo "
";
$rArr = mysql_fetch_row($result);
#查询结果的一行保存至数组中,下标从0开始,每一个数组元素对应一个哉
#通过循环可以将查询结果全部获得
echo "$rArr
";
print_r($rArr);echo "
";
echo $rArr[0];echo "
";
while ($row = mysql_fetch_array($result)) {
#与mysql_fetch_row功能基本相同,除mysql_fetch_row的功能外还可用域名作索引
echo $row[name].$row[id]."
";
}
echo $rArr[id];echo "
";
echo "
";
mysql_query("set names 'GBK'");//解决中文乱码问题
#mysql_num_rows($result);#用于计算查询结果中所统计局行的数目
mysql_insert_id();#传回最后一次使用insert指令的id
mysql_tablename($result, $i);#取得数据库名称
mysql_error();#返回错误信息
mysql_close();#关闭mysql连接
#mysql_fetch_array($result);
#echo $result;
?>