[root@localhost ~]# yum httpd php php-mysql mysql mysql-server-y
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database hele;
Query OK, 1 row affected (0.00 sec)
mysql> use hele;
Database changed
mysql> create table haha(name char(10), phy int, eng int, math int);
Query OK, 0 rows affected (0.06 sec)
mysql> insert into haha values ('xiaobai',85,90,70);
Query OK, 1 row affected (0.10 sec)
mysql> insert into haha values ('gh',85,90,70);
Query OK, 1 row affected (0.00 sec)
mysql> insert into haha values ('djk',70,80,85);
Query OK, 1 row affected (0.01 sec)

[root@localhost ~]# vim /var/www/html/mysql.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
        {
        die('Could not connect:' . mysql_error());
        }

mysql_select_db("hele", $con);

$result = mysql_query("SELECT * FROM haha");

while($row = mysql_fetch_array($result))
        {
        echo $row['name'] . " " . $row['phy'];
        echo "<br />";
        }
mysql_close($con);
?>

http://127.0.0.1/mysql.php

 

2013-1-29lamp作业_version