贴一段PHP读取数据库代码,结束今天的PHP之旅。。初步印象还是如大家所说,PHP是比较好学的,但是如何发挥出强大的效果,一个需要长期的经验积累,还有就是结合HTML、JS、CSS等其他前端大佬的配合。代码如下:
<?php echo $_SERVER['SCRIPT_NAME'].'<BR>';?> <?php $user = "root"; $passwd = "fireling"; $connect = mysql_connect('localhost', $user, $passwd) or die('数据库连接失败: '.mysql_error()); echo '第一步:成功建立连接!<BR>'; $db = 'test'; mysql_select_db($db) or die('Could not select database ('.$db.') because of: '.mysql_error()); echo '第二步:成功连接到('.$db.')!<BR>'; $query = 'SELECT * FROM employee'; $result = mysql_query($query) or die('Query failed: '.mysql_error()); $count = 0; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { foreach ($line as $col_value) { echo "$col_value\t"; } $count++; } mysql_free_result($result); mysql_close($connect); ?>