linux 下將mysql數據庫中的表內容顯示到網頁上

在虛擬機裏面做了一遍,實驗成功後複製的命令:

yum -y install httpd

 /etc/init.d/httpd restart
cd /var/www/html/
echo benwen > index.html

elinks http://192.168.18.2 --dump

   benwen

yum -y install mysql mysql-server

use test;

create table gya (name char(20), tel int, addr char(50));

mysql> desc gya;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name  | char(10) | YES  |     | NULL    |       |
| tel   | int(11)  | YES  |     | NULL    |       |
| addr  | char(50) | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
 

yum -y install php 
cd /etc/httpd/conf.d

 cd /etc/httpd/conf.d/

/etc/init.d/httpd  restart

cd /var/www/html/

vim  mysql.php

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

mysql_select_db("test", $con);

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

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

 yum -y php-mysql
   81  yum -y install php-mysql
   82  /etc/init.d/httpd restart
   83  elinks http://192.168.18.2/mysql.php --dump
   84  history
   85  elinks http://192.168.18.2 --dump

 benwen

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章