国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

PHP+MYSQL建設(shè)網(wǎng)站程序需要注意兩點(diǎn)

2024-07-24 12:56:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一、10句話(huà)

1.不要依賴(lài)register_global=on的環(huán)境,從你剛懂得配置php運(yùn)行環(huán)境甚至尚不明白register_global的on/off會(huì)對(duì)自己有什么影響的那天起,就應(yīng)該勇敢地把它設(shè)為off.

2.寫(xiě)程序前看看怎么用error_reporting.

3.不懂就問(wèn)本身沒(méi)錯(cuò),但你需要在那之前查查手冊(cè)。

4.當(dāng)然,你需要懂得使用手冊(cè)。手冊(cè)上找不到答案的時(shí)候,應(yīng)該考慮下網(wǎng)絡(luò)上的搜索引擎。

5.剛學(xué)會(huì)php+mysql之后,不要叫嚷著要寫(xiě)論壇,要寫(xiě)xxx。要明白,剛學(xué)會(huì)寫(xiě)漢字并不表示你有能力寫(xiě)詩(shī)。

6.在學(xué)web編程的時(shí)候,你應(yīng)該先去認(rèn)識(shí)html這個(gè)朋友。

7.有點(diǎn)能力后,試著回答新手的問(wèn)題,不要看到自己懂的而別人不懂就沾沾自喜,扔下一名“簡(jiǎn)單,那是基本的東西”就走更要不得。

8.思考是一個(gè)好習(xí)慣,不動(dòng)手去寫(xiě)就等于空想,什么也沒(méi)有。

9.寫(xiě)好一段程序,如果覺(jué)得很滿(mǎn)意,一周后再看一遍,也許你會(huì)認(rèn)為它應(yīng)該有所改變

10.有空多看看別人的程序,找出他人的不足或優(yōu)點(diǎn),自己掂量。

二. 各取所需

1.善于使用“引用”,它能直接影響到程序的效率。

2.善于用三元運(yùn)算子,可以讓程式較精簡(jiǎn)有效率。
比如:

php代碼:

if ($data[$i]['nickname']){
    $nickname =  $data[$i]['nickname'];
}
else{
    $nickname =  $data[$i]['ip'];
}

可以寫(xiě)成:

php代碼:

$nickname =  $data[$i]['nickname'] ? $data[$i]['nickname'] : $data[$i]['ip'];

3.善于組織if...else...回圈

比如:

php代碼:

$ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));
if (!empty($type))
{
    if (!strpos($type, $ext_name))
    {
        echo "please upload the file of $type form.";
        exit();
   }
}

上面的代碼你應(yīng)該寫(xiě)成這樣:

php代碼:

$ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));
if (!($type==='') && strpos($type, $ext_name)===false)
{
    echo "please upload the file of $type form.";
    exit();
}

4.盡量讓你的代碼清淅些,如果寫(xiě)成這樣,是比較讓人頭痛的:

php代碼:

$foo=$_post["foo"];
   $username=$_post["user"];
 $group=$_post["group"];
if ($group=="wheel")
{
$username=$username."wheel";
}

同樣的代碼,這樣就比較讓人看得舒服了:

php代碼:

$foo      = $_post["foo"];
$username = $_post["username"];
$group    = $_post["group"];
if ($group=="wheel")
{
    $username = $username."wheel";
}

當(dāng)然,有一定基礎(chǔ)后,你應(yīng)該要寫(xiě)成這樣:

php代碼:

$foo      = &$_post['foo'];
$username =  $_post["group"]!='wheel' ? $_post["username"] : $_post["username"].'wheel';

5.編寫(xiě)規(guī)范的mysql 語(yǔ)句。

字段和表名用"`"引起來(lái),避免保留字的影響。
如果看到下面這樣的一個(gè)sql query,會(huì)讓人比較頭痛:

php代碼:

$query="select `flash_comment`.`content` , `flash_comment`.`nickname` , `flash_comment`.`date` , `flash_comment`.`ip` , `product`.`p_name` , `sgflash`.`fid` from `flash_comment` left join `product` on ( `flash_comment`.`p_no` = `product`.`p_no` ) left join `sgflash` on ( `product`.`p_name` = `sgflash`.`f_name` ) where `flash_comment`.`p_no` != '' order by `flash_comment`.`date`";

同樣的一個(gè)query,寫(xiě)成這樣就令人看得明白得多了:

php代碼:

$query = "select `flash_comment`.`content` , `flash_comment`.`nickname` , `flash_comment`.`date` , `flash_comment`.`ip` , `product`.`p_name` , `sgflash`.`fid`           from `flash_comment`           left join `product` on ( `flash_comment`.`p_no` = `product`.`p_no` )           left join `sgflash` on ( `product`.`p_name` = `sgflash`.`f_name` )           where `flash_comment`.`p_no` != ''          order by `flash_comment`.`date`";

注冊(cè)會(huì)員,創(chuàng)建你的web開(kāi)發(fā)資料庫(kù),
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 迁安市| 潼南县| 扬中市| 同仁县| 手机| 彭州市| 福鼎市| 新平| 大余县| 达日县| 利津县| 达日县| 栾城县| 和平县| 和政县| 东乌珠穆沁旗| 紫云| 涡阳县| 阳原县| 怀集县| 鄄城县| 林口县| 沁水县| 竹北市| 广南县| 上虞市| 互助| 奉新县| 泸水县| 海宁市| 屏东市| 确山县| 武威市| 闵行区| 常熟市| 新沂市| 鹤山市| 杭州市| 彭山县| 公主岭市| 六安市|