新聞中心
關(guān)于PHP網(wǎng)頁(yè)和數(shù)據(jù)庫(kù)的問題。
PHP鏈接數(shù)據(jù)庫(kù)很簡(jiǎn)單的,用dreamwave自動(dòng)生成的代碼的話比較亂.
創(chuàng)新互聯(lián)公司提供高防服務(wù)器租用、云服務(wù)器、香港服務(wù)器、光華機(jī)房服務(wù)器托管等
給你一個(gè)例子
?php
//鏈接數(shù)據(jù)庫(kù),如果鏈接不成功則提示"無(wú)法鏈接數(shù)據(jù)庫(kù)"
$db=mysql_connect("數(shù)據(jù)庫(kù)服務(wù)器地址","帳號(hào)","密碼" ) or die("無(wú)法鏈接數(shù)據(jù)庫(kù)服務(wù)器");
//選擇數(shù)據(jù)庫(kù),注意數(shù)據(jù)庫(kù)服務(wù)和數(shù)據(jù)庫(kù)的區(qū)別
mysql_select_db("數(shù)據(jù)庫(kù)的名字") or die("無(wú)法鏈接數(shù)據(jù)庫(kù)");
//OK到此之后我們就可以對(duì)你選擇的數(shù)據(jù)庫(kù)進(jìn)行操作了.
mysql_query("你需要查詢的SQL語(yǔ)句");
?
另外送上PHP常用的mysql函數(shù)
mysql_affected_rows: 得到 MySQL 最后操作影響的列數(shù)目。
mysql_close: 關(guān)閉 MySQL 伺服器連線。
mysql_connect: 開啟 MySQL 伺服器連線。
mysql_create_db: 建立一個(gè) MySQL 新資料庫(kù)。
mysql_data_seek: 移動(dòng)內(nèi)部傳回指標(biāo)。
mysql_db_query: 送查詢字串 (query) 到 MySQL 資料庫(kù)。
mysql_drop_db: 移除資料庫(kù)。
mysql_errno: 傳回錯(cuò)誤訊息代碼。
mysql_error: 傳回錯(cuò)誤訊息。
mysql_fetch_array: 傳回陣列資料。
mysql_fetch_field: 取得欄位資訊。
mysql_fetch_lengths: 傳回單列各欄資料最大長(zhǎng)度。
mysql_fetch_object: 傳回物件資料。
mysql_fetch_row: 傳回單列的各欄位。
mysql_field_name: 傳回指定欄位的名稱。
mysql_field_seek: 設(shè)定指標(biāo)到傳回值的某欄位。
mysql_field_table: 獲得目前欄位的資料表 (table) 名稱。
mysql_field_type: 獲得目前欄位的型態(tài)。
mysql_field_flags: 獲得目前欄位的旗標(biāo)。
mysql_field_len: 獲得目前欄位的長(zhǎng)度。
mysql_free_result: 釋放傳回占用記憶體。
mysql_insert_id: 傳回最后一次使用 INSERT 指令的 ID。
mysql_list_fields: 列出指定資料表的欄位 (field)。
mysql_list_dbs: 列出 MySQL 伺服器可用的資料庫(kù) (database)。
mysql_list_tables: 列出指定資料庫(kù)的資料表 (table)。
mysql_num_fields: 取得傳回欄位的數(shù)目。
mysql_num_rows: 取得傳回列的數(shù)目。
mysql_pconnect: 開啟 MySQL 伺服器長(zhǎng)期連線。
mysql_query: 送出一個(gè) query 字串。
mysql_result: 取得查詢 (query) 的結(jié)果。
mysql_select_db: 選擇一個(gè)資料庫(kù)。
mysql_tablename: 取得資料表名稱
怎樣用php+mysql 做一個(gè)查詢的網(wǎng)頁(yè)
首先搭建一個(gè)PHP環(huán)境,我用的wamp
然后比如你的數(shù)據(jù)庫(kù)位置是本地localhost
數(shù)據(jù)庫(kù)用戶名是root
數(shù)據(jù)庫(kù)密碼是123456
數(shù)據(jù)庫(kù)名是mydb
數(shù)據(jù)庫(kù)里有個(gè)表mytab
有3個(gè)字段
id(主鍵) name sno
1 張三 123
2 李四 456
然后在項(xiàng)目根目錄,新建一個(gè)文件:index.php
?php
//連接數(shù)據(jù)庫(kù)
$con=mysqli_connect("localhost","root","123456","mydb");
//SQL語(yǔ)句
$sql="select * from mytab;";
//執(zhí)行SQL語(yǔ)句,結(jié)果保存到$arr
$obj=mysqli_query($con,$sql);
$arr=mysqli_num_rows($result);
?
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
title實(shí)現(xiàn)最簡(jiǎn)單的php網(wǎng)頁(yè)+mysql查詢功能/title
/head
body
?php
echo "pre";
print_r($obj);
?
/body
/html
之后就能夠看到結(jié)果了
(PHP)從數(shù)據(jù)庫(kù)查詢出產(chǎn)品數(shù)據(jù) 怎樣把它很有整齊的顯示在網(wǎng)頁(yè)上 ?
?php
//第一步:透過代理獲取用戶真實(shí)的IP地址
$theip=getip();
function getIP()
{
static $realip;
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
$realip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
//第二步:通過讀取IP地址庫(kù),找到所屬地區(qū)
//假設(shè)表名為ip,字段有begin(起始),end(結(jié)束),area(地區(qū)代號(hào))
$dblink=@mysql_connect("數(shù)據(jù)庫(kù)服務(wù)器名","數(shù)據(jù)庫(kù)用戶名","數(shù)據(jù)庫(kù)密碼");
$dbselect=@mysql_select_db(數(shù)據(jù)庫(kù)名);
if (!$dbselect){
die("數(shù)據(jù)庫(kù)無(wú)法讀取");
}
$result=mysql_query("select * from `ip` where `begin`=`$theip` and `end`=`$theip`");
$num=mysql_num_rows($result);
if($num0){
$info=mysql_fetch_array($result);
$page=$info['area'];
else{
$page='default'; //如果IP不在數(shù)據(jù)庫(kù)中,則用缺省的頁(yè)面
}
//第三步:轉(zhuǎn)到相關(guān)頁(yè)面,如代號(hào)為"js",轉(zhuǎn)到"js.php"頁(yè)面
$page.='.html'; //后綴你可以自己取
echo "script language=\"javascript\"window.location.replace(\"$page\")/script";
?
文章題目:php的數(shù)據(jù)庫(kù)網(wǎng)頁(yè) Php數(shù)據(jù)庫(kù)
鏈接地址:http://fisionsoft.com.cn/article/docepjh.html