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

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

PHP+MySQL扎實基本功

2024-07-24 12:57:03
字體:
供稿:網(wǎng)友

一. 10句話
1.不要依賴register_global=on的環(huán)境,從你剛懂得配置php運行環(huán)境甚至尚不明白register_global的on/off會對自己有什么影響的那天起,就應(yīng)該勇敢地把它設(shè)為off.
2.寫程序前看看怎么用error_reporting.
3.不懂就問本身沒錯,但你需要在那之前查查手冊。
4.當(dāng)然,你需要懂得使用手冊。手冊上找不到答案的時候,應(yīng)該考慮下網(wǎng)絡(luò)上的搜索引擎。
5.剛學(xué)會php+mysql之后,不要叫嚷著要寫論壇,要寫xxx。要明白,剛學(xué)會寫漢字并不表示你有能力寫詩。
6.在學(xué)web編程的時候,你應(yīng)該先去認識html這個朋友。
7.有點能力后,試著回答新手的問題,不要看到自己懂的而別人不懂就沾沾自喜,扔下一名“簡單,那是基本的東西”就走更要不得。
8.思考是一個好習(xí)慣,不動手去寫就等于空想,什么也沒有。
9.寫好一段程序,如果覺得很滿意,一周后再看一遍,也許你會認為它應(yīng)該有所改變
10.有空多看看別人的程序,找出他人的不足或優(yōu)點,自己掂量。

二. 各取所需

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

2.善于用三元運算子,可以讓程式較精簡有效率。
比如:

php代碼:

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

可以寫成:

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)該寫成這樣:

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.盡量讓你的代碼清淅些,如果寫成這樣,是比較讓人頭痛的:

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)該要寫成這樣:

php代碼:

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

5.編寫規(guī)范的mysql 語句。

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

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`";

同樣的一個query,寫成這樣就令人看得明白得多了:

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`";

國內(nèi)最大的酷站演示中心!
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 西乌珠穆沁旗| 荣成市| 潼关县| 敦煌市| 扎赉特旗| 西峡县| 二连浩特市| 屏山县| 金华市| 蓬莱市| 高雄县| 常宁市| 明星| 娱乐| 应用必备| 赣州市| 毕节市| 商河县| 清涧县| 宜都市| 鹤庆县| 宜兰县| 友谊县| 台湾省| 修武县| 博爱县| 枣阳市| 康定县| 通化市| 高青县| 常宁市| 永新县| 双峰县| 洱源县| 柳江县| 海门市| 安宁市| 天镇县| 邵东县| 会昌县| 保德县|