課程
/后端開發(fā)
/PHP
/手把手教你實現(xiàn)電商網(wǎng)站后臺開發(fā)
誰能把你寫的發(fā)給我一下 我的那個index.php一直進不去啊?說mysqli_fetch_array 為null ,不知道為什么
2016-07-07
源自:手把手教你實現(xiàn)電商網(wǎng)站后臺開發(fā) 2-3
正在回答
?//定義連接mysql數(shù)據(jù)庫的連接字符串
? ? function connect()
? ? {
? ? ? ? //連接數(shù)據(jù)庫
? ? ? ? $host='127.0.0.1';
? ? ? ? $root='phpuser';
? ? ? ? $pwd='123456';
? ? ? ? //打開需要操作的數(shù)據(jù)庫寫入數(shù)據(jù)庫
? ? ? ? $mysql_database='phptest';
? ? ? ? $link = mysqli_connect($host, $root,$pwd, $mysql_database);
? ? ? ? //設(shè)置插入字符的格式,gb2312這里必須設(shè)置。否則插入不了漢字
? ? ? ? mysqli_query($link,"set names gb2312");
? ? ? ? if($link==false){
? ? ? ? ? ? // ? ? ? 如果連接失敗
? ? ? ? ??
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? return $link;
? ? ? ? ? ? //mysql_query("set names 'utf8'");//設(shè)置數(shù)據(jù)庫輸出編碼
? ? ? ? ? ? //mysql_select_db($mysql_database);//打開數(shù)據(jù)庫
? ? }
?//判斷登錄人是否是管理員,如果是管理員,那么就返回true,如果不是則返回
? ? function fetchOne($sql){
? ? ? ? $link=connect();
? ? ? ? $result=mysqli_query($link,$sql);//執(zhí)行SQL語句
? ? ? ? $row=mysqli_fetch_array($result);
? ? ? ? mysqli_close($link);//關(guān)閉數(shù)據(jù)庫連接
? ? ? ? return $row;
親,給分吧
大斌子123
舉報
手把手教你用PHP搭建電子商務(wù)平臺,由淺入深教你搭建電商系統(tǒng)
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-07-12
?//定義連接mysql數(shù)據(jù)庫的連接字符串
? ? function connect()
? ? {
? ? ? ? //連接數(shù)據(jù)庫
? ? ? ? $host='127.0.0.1';
? ? ? ? $root='phpuser';
? ? ? ? $pwd='123456';
? ? ? ? //打開需要操作的數(shù)據(jù)庫寫入數(shù)據(jù)庫
? ? ? ? $mysql_database='phptest';
? ? ? ? $link = mysqli_connect($host, $root,$pwd, $mysql_database);
? ? ? ? //設(shè)置插入字符的格式,gb2312這里必須設(shè)置。否則插入不了漢字
? ? ? ? mysqli_query($link,"set names gb2312");
? ? ? ? if($link==false){
? ? ? ? ? ? // ? ? ? 如果連接失敗
? ? ? ? ??
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? return $link;
? ? ? ? ? ? //mysql_query("set names 'utf8'");//設(shè)置數(shù)據(jù)庫輸出編碼
? ? ? ? ? ? //mysql_select_db($mysql_database);//打開數(shù)據(jù)庫
? ? ? ? }
? ? }
?//判斷登錄人是否是管理員,如果是管理員,那么就返回true,如果不是則返回
? ? function fetchOne($sql){
? ? ? ? $link=connect();
? ? ? ? $result=mysqli_query($link,$sql);//執(zhí)行SQL語句
? ? ? ? $row=mysqli_fetch_array($result);
? ? ? ? mysqli_close($link);//關(guān)閉數(shù)據(jù)庫連接
? ? ? ? return $row;
? ? }
親,給分吧