首页  >  文章  >  后端开发  >  php 从mysql中读取数据

php 从mysql中读取数据

巴扎黑
巴扎黑原创
2016-11-23 10:50:56925浏览

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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn