mysqli有兩種數(shù)據(jù)庫(kù)敬好連接方式:
建網(wǎng)站原本是網(wǎng)站策劃師、網(wǎng)絡(luò)程序員、網(wǎng)頁(yè)設(shè)計(jì)師等,應(yīng)用各種網(wǎng)絡(luò)程序開(kāi)發(fā)技術(shù)和網(wǎng)頁(yè)設(shè)計(jì)技術(shù)配合操作的協(xié)同工作。成都創(chuàng)新互聯(lián)公司專(zhuān)業(yè)提供網(wǎng)站建設(shè)、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站制作(企業(yè)站、響應(yīng)式網(wǎng)站設(shè)計(jì)、電商門(mén)戶(hù)網(wǎng)站)等服務(wù),從網(wǎng)站深度策劃、搜索引擎友好度優(yōu)化到用戶(hù)體驗(yàn)的提升,我們力求做到極致!
1、面向過(guò)程式連接攜梁:
mysqli_connect('localhost','xxx','xxx','xxx');
mysqli_query('');
后使用mysqli_fetch_assoc方辯稿運(yùn)法獲取到數(shù)據(jù)。
2、面向?qū)ο笫竭B接:
$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");
$result?=?$mysqli-query('');
后使用$result-fetch_assoc()獲取數(shù)據(jù)。
至于num_rows是獲取查詢(xún)到的行數(shù)的方法。
查看一下代碼:
?php
//?獲取表單提交值
$student_id?=?intval(trim($_POST['student_id']));
//?頁(yè)面表單??可以放單缺純畢獨(dú)的html文件中,如果放單獨(dú)的html頁(yè)面中?form?的action的地址要改成下面的PHP文件名
echo?'form?action=""?method="post"
input?type="text"?name="student_id"?value="{$student_id}"/
input?type="submit"?name="submit"?value="查詢(xún)"/
/form';
//?當(dāng)有數(shù)據(jù)提交時(shí)
if?($student_id)
{
$con=?mysql_connect("褲凱localhost","root","111")?or?die("連接錯(cuò)誤");
mysql_select_db("examination",$con);
//?查詢(xún)
$sql?伏芹=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//?輸出
echo?'學(xué)號(hào):'.$row['student_id'].'br姓名:'.$row['name'].'br性別:'.$row['gender'].'br分?jǐn)?shù):'.$row['score'];
}
?
你寫(xiě)的單引號(hào),變量直接當(dāng)字符串使用了,$s_spid沒(méi)有被解析成對(duì)應(yīng)的值
最簡(jiǎn)單的方法是使用IN、NOT IN來(lái)查詢(xún)存在、不存在,很好理解,枯纖下面是查詢(xún)不存在的例子:派敗空
select * from a where tid not in (select tid from b)
但是不知塵瞎道你的mysql是否支持這樣的子查詢(xún),如果不支持,就用你的連接,例子如下:
select a.*,b.tid from a left join b on a.tid=b.tid where b.tid is null
注意,要使用左連接(LEFT JOIN),條件是B.TID為空。
分享文章:php查詢(xún)構(gòu)造數(shù)據(jù) php查看結(jié)構(gòu)類(lèi)型變量的值
當(dāng)前鏈接:http://www.chinadenli.net/article36/ddpidsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、移動(dòng)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、品牌網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(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)容