1.不要依赖register_global=ON的环境,从你刚懂得配置php运行环境甚至尚不明白register_global的ON/OFF会对自己有什么影响的那天起,就应该勇敢地把它设为OFF.
2.写程序前看看怎么用error_reporting.
3.不懂就问本身没错,但你需要在那之前查查手册。
4.当然,你需要懂得使用手册。手册上找不到答案的时候,应该考虑下网络上的搜索引擎。
5.刚学会php+mysql之后,不要叫嚷着要写论坛,要写XXX。要明白,刚学会写汉字并不表示你有能力写诗。
6.在学web编程的时候,你应该先去认识html这个朋友。
7.有点能力后,试着回答新手的问题,不要看到自己懂的而别人不懂就沾沾自喜,扔下一名“简单,那是基本的东西”就走更要不得。
8.思考是一个好习惯,不动手去写就等于空想,什么也没有。
9.写好一段程序,如果觉得很满意,一周后再看一遍,也许你会认为它应该有所改变
10.有空多看看别人的程序,找出他人的不足或优点,自己掂量。
二. 各取所需
1.善于使用“引用”,它能直接影响到程序的效率。
2.善于用三元运算子,可以让程式较精简有效率。
比如:
<font size="2"><font face="Verdana">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br></font><font color="#007700">if (</font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'nickname'</font><font color="#007700">]) <br>{ <br> </font><font color="#0000bb">$nickname </font><font color="#007700">= </font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'nickname'</font><font color="#007700">]; <br>} <br>else <br>{ <br> </font><font color="#0000bb">$nickname </font><font color="#007700">= </font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'ip'</font><font color="#007700">]; <br>}<br></font><font color="#0000bb"></font> </font> </code><hr>
可以写成:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$nickname </font><font color="#007700">= </font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'nickname'</font><font color="#007700">] ? </font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'nickname'</font><font color="#007700">] : </font><font color="#0000bb">$data</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">][</font><font color="#dd0000">'ip'</font><font color="#007700">];<br></font><font color="#0000bb"></font> </font> </code><hr>
3.善于组织if...else...回圈
比如:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$ext_name </font><font color="#007700">= </font><font color="#0000bb">strtolower</font><font color="#007700">(</font><font color="#0000bb">str_replace</font><font color="#007700">(</font><font color="#dd0000">"."</font><font color="#007700">, </font><font color="#dd0000">""</font><font color="#007700">, </font><font color="#0000bb">strrchr</font><font color="#007700">(</font><font color="#0000bb">$upfilename</font><font color="#007700">, </font><font color="#dd0000">"."</font><font color="#007700">))); <br>if (!empty(</font><font color="#0000bb">$type</font><font color="#007700">)) <br>{ <br> if (!</font><font color="#0000bb">strpos</font><font color="#007700">(</font><font color="#0000bb">$type</font><font color="#007700">, </font><font color="#0000bb">$ext_name</font><font color="#007700">)) <br> { <br> echo </font><font color="#dd0000">"Please upload the file of $type form."</font><font color="#007700">; <br> exit(); <br> } <br>}<br></font><font color="#0000bb"></font> </font> </code><hr>
上面的代码你应该写成这样:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$ext_name </font><font color="#007700">= </font><font color="#0000bb">strtolower</font><font color="#007700">(</font><font color="#0000bb">str_replace</font><font color="#007700">(</font><font color="#dd0000">"."</font><font color="#007700">, </font><font color="#dd0000">""</font><font color="#007700">, </font><font color="#0000bb">strrchr</font><font color="#007700">(</font><font color="#0000bb">$upfilename</font><font color="#007700">, </font><font color="#dd0000">"."</font><font color="#007700">))); <br>if (!(</font><font color="#0000bb">$type</font><font color="#007700">===</font><font color="#dd0000">''</font><font color="#007700">) && </font><font color="#0000bb">strpos</font><font color="#007700">(</font><font color="#0000bb">$type</font><font color="#007700">, </font><font color="#0000bb">$ext_name</font><font color="#007700">)===</font><font color="#0000bb">false</font><font color="#007700">) <br>{ <br> echo </font><font color="#dd0000">"Please upload the file of $type form."</font><font color="#007700">; <br> exit(); <br>}<br></font><font color="#0000bb"></font> </font> </code><hr>
4.尽量让你的代码清淅些
如果写成这样,是比较让人头痛的:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$foo</font><font color="#007700">=</font><font color="#0000bb">$_post</font><font color="#007700">[</font><font color="#dd0000">"foo"</font><font color="#007700">]; <br> </font><font color="#0000bb">$username</font><font color="#007700">=</font><font color="#0000bb">$_post</font><font color="#007700">[</font><font color="#dd0000">"user"</font><font color="#007700">]; <br></font><font color="#0000bb">$group</font><font color="#007700">=</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"group"</font><font color="#007700">]; <br>if (</font><font color="#0000bb">$group</font><font color="#007700">==</font><font color="#dd0000">"wheel"</font><font color="#007700">){ <br></font><font color="#0000bb">$username</font><font color="#007700">=</font><font color="#0000bb">$username</font><font color="#007700">.</font><font color="#dd0000">"wheel"</font><font color="#007700">; <br>}<br></font><font color="#0000bb"></font> </font> </code><hr>
同样的代码,这样就比较让人看得舒服了:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$foo </font><font color="#007700">= </font><font color="#0000bb">$_post</font><font color="#007700">[</font><font color="#dd0000">"foo"</font><font color="#007700">]; <br></font><font color="#0000bb">$username </font><font color="#007700">= </font><font color="#0000bb">$_post</font><font color="#007700">[</font><font color="#dd0000">"username"</font><font color="#007700">]; <br></font><font color="#0000bb">$group </font><font color="#007700">= </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"group"</font><font color="#007700">]; <br>if (</font><font color="#0000bb">$group</font><font color="#007700">==</font><font color="#dd0000">"wheel"</font><font color="#007700">) <br>{ <br> </font><font color="#0000bb">$username </font><font color="#007700">= </font><font color="#0000bb">$username</font><font color="#007700">.</font><font color="#dd0000">"wheel"</font><font color="#007700">; <br>}<br></font><font color="#0000bb"></font> </font> </code><hr>
当然,有一定基础后,你应该要写成这样:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$foo </font><font color="#007700">= &</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">'foo'</font><font color="#007700">]; <br></font><font color="#0000bb">$username </font><font color="#007700">= </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"group"</font><font color="#007700">]!=</font><font color="#dd0000">'wheel' </font><font color="#007700">? </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"username"</font><font color="#007700">] : </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"username"</font><font color="#007700">].</font><font color="#dd0000">'wheel'</font><font color="#007700">;<br></font><font color="#0000bb"></font> </font> </code><hr>
5.编写规范的mysql 语句。
字段和表名用"`"引起来,避免保留字的影响。
如果看到下面这样的一个sql query,会让人比较头痛:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$query</font><font color="#007700">=</font><font color="#dd0000">"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`"</font><font color="#007700">;<br></font><font color="#0000bb"></font> </font> </code><hr>
同样的一个query,写成这样就令人看得明白得多了:
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$query </font><font color="#007700">= </font><font color="#dd0000">"SELECT `flash_comment`.`content` , `flash_comment`.`nickname` , `flash_comment`.`date` , `flash_comment`.`ip` , `product`.`p_name` , `sgflash`.`fid` <br> FROM `flash_comment` <br> LEFT JOIN `product` ON ( `flash_comment`.`p_no` = `product`.`p_no` ) <br> LEFT JOIN `sgflash` ON ( `product`.`p_name` = `sgflash`.`f_name` ) <br> WHERE `flash_comment`.`p_no` != '' <br> ORDER BY `flash_comment`.`date`"</font><font color="#007700">;<br></font><font color="#0000bb"></font> </font> </code><hr>
//

如何有效監控MySQL性能?使用mysqladmin、SHOWGLOBALSTATUS、PerconaMonitoringandManagement(PMM)和MySQLEnterpriseMonitor等工具。 1.使用mysqladmin查看連接數。 2.用SHOWGLOBALSTATUS查看查詢數。 3.PMM提供詳細性能數據和圖形化界面。 4.MySQLEnterpriseMonitor提供豐富的監控功能和報警機制。

MySQL和SQLServer的区别在于:1)MySQL是开源的,适用于Web和嵌入式系统,2)SQLServer是微软的商业产品,适用于企业级应用。两者在存储引擎、性能优化和应用场景上有显著差异,选择时需考虑项目规模和未来扩展性。

在需要高可用性、高級安全性和良好集成性的企業級應用場景下,應選擇SQLServer而不是MySQL。 1)SQLServer提供企業級功能,如高可用性和高級安全性。 2)它與微軟生態系統如VisualStudio和PowerBI緊密集成。 3)SQLServer在性能優化方面表現出色,支持內存優化表和列存儲索引。

mySqlManagesCharacterSetsetSandCollationsyutusututf-8asthEdeFault,允許ConfigurationAtdataBase,table和columnlevels,AndrequiringCarefullageLignmentToavoidMismatches.1)setDefeaultCharactersetTercharactersetEtCollacterSeteTandColletationForAdataBase.2)conformentcollecharactersettersetertersetcollatertersetcollationcollation

MySQL觸發器是與表相關聯的自動執行的存儲過程,用於在特定數據操作時執行一系列操作。 1)觸發器定義與作用:用於數據校驗、日誌記錄等。 2)工作原理:分為BEFORE和AFTER,支持行級觸發。 3)使用示例:可用於記錄薪資變更或更新庫存。 4)調試技巧:使用SHOWTRIGGERS和SHOWCREATETRIGGER命令。 5)性能優化:避免複雜操作,使用索引,管理事務。

在MySQL中創建和管理用戶賬戶的步驟如下:1.創建用戶:使用CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';2.分配權限:使用GRANTSELECT,INSERT,UPDATEONmydatabase.TO'newuser'@'localhost';3.修正權限錯誤:使用REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost';然後重新分配權限;4.優化權限:使用SHOWGRA

MySQL適合快速開發和中小型應用,Oracle適合大型企業和高可用性需求。 1)MySQL開源、易用,適用於Web應用和中小型企業。 2)Oracle功能強大,適合大型企業和政府機構。 3)MySQL支持多種存儲引擎,Oracle提供豐富的企業級功能。

MySQL相比其他關係型數據庫的劣勢包括:1.性能問題:在處理大規模數據時可能遇到瓶頸,PostgreSQL在復雜查詢和大數據處理上表現更優。 2.擴展性:水平擴展能力不如GoogleSpanner和AmazonAurora。 3.功能限制:在高級功能上不如PostgreSQL和Oracle,某些功能需要更多自定義代碼和維護。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

Dreamweaver CS6
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!