//1.連接數(shù)據(jù)庫(kù)

創(chuàng)新互聯(lián)是一家專業(yè)提供綏棱企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、H5場(chǎng)景定制、小程序制作等業(yè)務(wù)。10年已為綏棱眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
$link?=?@mysql_connect('localhost','root','123456');
//2.判斷是否連接成功
if(!$link)?exit('數(shù)據(jù)庫(kù)連接失敗');
//3.選擇數(shù)據(jù)庫(kù)
mysql_select_db('mydatabase');
//4.設(shè)置字符集??utf8
mysql_set_charset('utf8');
//5.準(zhǔn)備一個(gè)SQL語(yǔ)句
$sql?=?'select?*?from?user';
//6.發(fā)送SQL語(yǔ)句
$result?=?mysql_query($sql);
//7.判斷并處理返回結(jié)果
if($result){
while($row?=?mysql_fetch_array($result)){
$list[]?=?$row;
}
echo?"pre";
print_r($list);
echo?"/pre";
}
//8.釋放資源
mysql_free_result($result);???//查詢操作才需要釋放結(jié)果集
mysql_close();
這個(gè)簡(jiǎn)單啊!
首頁(yè)做個(gè)前臺(tái)輸入姓名和會(huì)員卡信息的頁(yè)面,我做個(gè)簡(jiǎn)單的頁(yè)面給你看
!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"
html?xmlns="
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/
title會(huì)員查詢系統(tǒng)/title
/head
body
form?id="form1"?name="form1"?method="post"?action="test.php"
p
label?for="name"/label
input?type="text"?name="name"?id="name"?/
/p
p
label?for="vipid"/label
input?type="text"?name="vipid"?id="vipid"?/
/p
p
input?type="submit"?name="button"?id="button"?value="查詢"?/
/p
/form
/body
/html
然后我給你一個(gè)test.php的文件代碼:
?php
$name????=????trim($_POST['name']);
$vipid????=????trim($_POST['vipid']);
$con?=?mysql_connect("127.0.0.1","數(shù)據(jù)庫(kù)用戶名","數(shù)據(jù)庫(kù)密碼");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
$a????=????mysql_select_db("數(shù)據(jù)庫(kù)名字",?$con);
$sql????=????"select?*?from?kh_customer?where?name?=?'$name'?and?vipid?=?'$vipid'";
$result?=?mysql_query($sql);
while($row?=?mysql_fetch_array($result))
{
echo?$row['name']?.?"?"?.?$row['data'];
echo?"br?/";
}
mysql_close($con);
?
頁(yè)面美化自己去搞!只能幫你這么多了
mysqli有兩種數(shù)據(jù)庫(kù)連接方式:
1、面向過(guò)程式連接:
mysqli_connect('localhost','xxx','xxx','xxx');
mysqli_query('');
后使用mysqli_fetch_assoc方法獲取到數(shù)據(jù)。
2、面向?qū)ο笫竭B接:
$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");
$result?=?$mysqli-query('');
后使用$result-fetch_assoc()獲取數(shù)據(jù)。
至于num_rows是獲取查詢到的行數(shù)的方法。
                本文標(biāo)題:php7怎么查詢數(shù)據(jù)庫(kù) phpstudy查看數(shù)據(jù)庫(kù)
                
                轉(zhuǎn)載來(lái)源:http://chinadenli.net/article18/ddgeodp.html
            
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、網(wǎng)站排名、全網(wǎng)營(yíng)銷推廣、企業(yè)網(wǎng)站制作、搜索引擎優(yōu)化、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容