mysql山推 談PHP MySQL紮實個人基本功

2021-10-18 22:21:35 字數 3001 閱讀 5974

談php+mysql紮實個人基本功

不要依賴register_global=on的環境,從你剛懂得配置php執行環境甚至尚不明白register_global的on/off會對自己有什麼影響的那天起,就應該勇敢地把它設為off.

一. 10句話

1.不要依賴register_global=on的環境,從你剛懂得配置php執行環境甚至尚不明白register_global的on/off會對自己有什麼影響的那天起,就應該勇敢地把它設為off.

2.寫程式前看看怎麼用error_reporting.

3.不懂就問本身沒錯,但你需要在那之前查查手冊。

4.當然,你需要懂得使用手冊。手冊上找不到答案的時候,應該考慮下網路上的搜尋引擎。

5.剛學會php+mysql之後,不要叫嚷著要寫論壇,要寫***。要明白,剛學會寫漢字並不表示你有能力寫詩。

6.在學web程式設計的時候,你應該先去認識html這個朋友。

7.有點能力後,試著回答新手的問題,不要看到自己懂的而別人不懂就沾沾自喜,扔下一名「簡單,那是基本的東西」就走更要不得。

8.思考是乙個好習慣,不動手去寫就等於空想,什麼也沒有。

9.寫好一段程式,如果覺得很滿意,一周後再看一遍,也許你會認為它應該有所改變

10.有空多看看別人的程式,找出他人的不足或優點,自己掂量。

二. 各取所需

1.善於使用「引用」,它能直接影響到程式的效率。

2.善於用三元運運算元,可以讓程式較精簡有效率。

比如:code:

if ($data[$i]['nickname'])

$nickname = $data[$i]['nickname'];

else

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

可以寫成:

code:

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

3.善於組織if...else...迴圈

比如:code:

$ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));

if (!empty($type))

if (!strpos($type, $ext_name))

echo "please upload the file of $type form.";

exit();

上面的**你應該寫成這樣:

code:

$ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));

if (!($type==='') && strpos($type, $ext_name)===false)

echo "please upload the file of $type form.";

exit();

4.盡量讓你的**清淅些

如果寫成這樣,是比較讓人頭痛的:

code:

$foo=$_post["foo"];

$username=$_post["user"];

$group=$_post["group"];

if ($group=="wheel")

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

code:

$foo   = $_post["foo"];

$username = $_post["username"];

$group  = $_post["group"];

if ($group=="wheel")

$username = $username."wheel";

當然,有一定基礎後,你應該要寫成這樣:

code:

$foo   = &$_post['foo'];

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

5.編寫規範的mysql 語句。

欄位和表名用"`"引起來,避免保留字的影響。

如果看到下面這樣的乙個sql query,會讓人比較頭痛:

code:

$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,寫成這樣就令人看得明白得多了:

code:

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

mysql山推 mysql儲存過程基本函式

一.字串類 charset str 返回字串字符集 concat string2 連線字串 instr string substring 返回substring首次在string 現的位置,不存在返回0 lcase string2 轉換成小寫 left string2 length 從string2...

php輸入框mysql互動 php mysql互動

1.接受資料 if post else msg 賬號或者密碼錯誤 conn close 4.獲取mysql報錯資訊 coon error 二 檔案上傳 if files 1.獲取檔案字尾 temp explode files img name extension end temp 2.判斷檔案型別和...

mysql索引簡談

mysql索引簡談 一 什麼是索引 就好比我們在看一本書的時候,有目錄的話,我們可以快速定位到想看的地方,而沒有目錄的話,我們只能一頁一頁地翻。索引就像目錄,有了索引,資料庫可以快速查詢到目標內容,而不必查詢整個資料庫表,但是如果沒有的話,資料庫只能一行一行地遍歷資料。create table t ...