当前位置:Gxlcms > PHP教程 > php从mysql中读取数据

php从mysql中读取数据

时间:2021-07-01 10:21:17 帮助过:27人阅读

<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = 'root';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
 die('Could not connect to mysql');
}
echo "connected successfully!";
$sql = 'SELECT emp_id, emp_name, emp_salary FROM employee';
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
 die('Could not get data: ');
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "EMP ID :{$row['emp_id']}  <br> ".
"EMP NAME : {$row['emp_name']} <br> ".
"EMP SALARY : {$row['emp_salary']} <br> ".
"--------------------------------<br>";
} 
echo "Fetched data successfully\n";
mysql_close($conn);
?>

人气教程排行