Why to use php? Experience in making php websites
Source: Shangpin China |
Type: website encyclopedia |
Date: July 20, 2012
outline ● Know PHP Website production ● PHP design experience – Why use a template – Why use the database interface – What is PEAR – PHP + MySQL4.1s
2. Know PHP ● Cross platform web programming language ● What PHP can do ● A large number of OpenSource suites
3 Cross platform PHP ● LAMP – Linux + Apache + MySQL + PHP ● Almost all Linux Dist presets have these kits ● WAMP – Windows + Apache + MySQL + PHP ● Rapid environment establishment – Appserv – Easyphp ● PHP For IIS
4 What PHP can do ● Server-side scripting – Web programming ● Command line scripting – Use PHP to write shell scripts ● Client-side GUI applications – PHP-GTK
5. A large number of OpenSource suites (1) ● Forum: – phpBB2 ● CMS – Xoops – Mambo,Joomla – PhpNuke – postnuke ● Calender – PHP iCalendar – phpCalendar – EasyPHPCalendar
6. A large number of OpenSource suites (2)
● Groupware – Egroupware – DotProject – Phpgroupware ● List – PHPList ● Webmail – Squirrelmail ● Blog – WordPress – Plog
7 Questions for beginners
● The code is written directly in HTML – Most of the books on the market use this as teaching – Most PHP books on the market do not mention the prototype system – Get used to outputting data directly with echo ● Not familiar with HTML – Use of cross row and cross column tables – Form design – When to use POST and GET ● Not used to working in register_globals=Off ● Unfamiliarity with error messages – Fear of English?
8 To what extent is not a novice?
● Clearly understand the difference between the Server side and the Client side ● Clearly understand the significance of register_globals setting ● Do not confuse the difference between logical judgment and variable value assignment
● Clearly understand the relationship and difference between POST and GET, COOKIE and Session ● Basic error messages can be interpreted ● Basic HTML analysis capability – Common TAG analysis and parameter use – TABLE tag structure analysis
9PHP design experience
● PHP programming standards ● Several advanced courses can be considered for learning – Establish a standard archive structure – Be familiar with at least one sample program – Using the database interface – Use PEAR more often ● MySQL4.1 – Sub-Select – Impact of Charset
10 Establish a standard archive structure
● You should establish a standard archive directory structure – Where should I put the library? – Where should the sample be placed? – Plug in? – Is there a website profile? – Is there a management interface? ● Refer to several current OpenSource CMS – Xoops, phpbb2, mambo, etc ● Can be simple, not complex
11PHP Programming Standards
● Benefits of setting project programming standards – Variables, objects and functions have fixed naming methods – The program style of the project is unified, reducing the maintenance complexity ● Do not change standards arbitrarily for ongoing projects – Standard setting should be decided at the beginning of the project – The standard setting should be discussed and decided by the project participants ● Design standard data available for reference – PHP programming standards
12Beyond PHP programming standards (1)
● The method that should be used when building the entire website – Use at least three-tier programming ● Presentation layer - actual output html ● Logic layer - handler flow ● Data processing layer - processing data access
– Use MVC (Model View Controller) to build your website - Function, do not output data directly in the object ● Try to use the return $html method
13 Beyond PHP programming standards (2)
● Should echo or printf be used? – Use echo to output general strings – Output strings containing variables with printf ● printf('a href='%s' target='%s'>%s</a>',$url,$target,$name); ● printf('a href='%s' target='%s'>%s</a>',array($url,$target,$name)); – Use sprintf when creating SQL syntax ● $SQL = sprintf('Select * from %s where ID = %s',$tableName,$id);
14 Be familiar with at least one sample program
● Why do you want to use a template? ● Two sets of sample programs recommended by me – Smarty – TBS
15 Why do you want to use the template?
● Don't let today's program become the burden of tomorrow's maintenance ● Art design is no longer worried about pages that are all code ● Programming is no longer worried about programs that are all HTML Tags ● Website design revision will be easy
16 Code without template
Code using templates
Web page template file
Officially recommended Smarty
● Sample engine recommended by Smarty for PHP – //smarty.php.net ● Smarty uses pre compiled templates – Fast ● Smarty can directly assign objects, arrays, etc ● Smarty provides global variables – $smarty.get , $smarty.post ,$smarty.server ● Smarty can directly output static pages for cache ● Smarty supports the use of plug-in modules – SmartyValidate
20 Lightweight Smarty lite
● It is more suitable for simple template demand environment ● Faster than Smarty ● Less system memory requirements ● Less functions than Smarty - Unable to assign object – Less filters before, during and after output – The mode of sample saving to database is not supported
21 Small and powerful TBS
● TBS – TinyButStrong – //www.tinybutstrong.com ● WYSIWYG prototype engine ● Support Cache ● Direct access to database display data – $TBS->MergeBlock('blk1',$cnx_id,'select *from t_country',$p_size,$p_num,$nbr_rec);
22 Why do I use the database interface?
● To write PHP programs for common databases ● More convenient database function ● Reduce the complexity of programming
23ADOdb
● Lower the learning threshold for Windows programmers – Some interfaces are designed like Microsoft's ADO ● Support multiple databases – MySQL,PgSQL,Oracle,MSSQL etc...... ● Many convenient methods are added to make programming easier – SelectLimit
– PageExecute,AtfirstPage,AtLastPage,Absolut ePage – getInsertSQL,getUpdateSQL,autoExecute ● Database cache, the same data does not need to read the database again – CacheExecute – CachePageExecute 24
ADOdb-lite
● ADOdb lite is a compact version of ADOdb ● Database support is almost equal ● Many functions provided by ADOdb are missing ● It also reduces the consumption of many system memories
25ADOdb development example
● Design paging function – There are many applications of paging function ● Message board, discussion area, data list, order list etc – $rs = $db->PageExecute($sql,$onePageStep,$_GET['page']); if(!$rs->AtFirstPage()){ ...//Perform the connection output of the previous page } if(!$rs->AtLastPage()){ ...//Perform the next page of connection output }
26 What is PEAR
● PHP Extension and Application Repository – //pear.php.net/ – Perl like CPAN – Provide installation program and update upgrade program pear ● A total of 31 categories of program packages are available – Common ones like Database HTML Mail Networking
27 Install the kit provided by pear
● Common pear commands
● Dependent kits will be prompted during installation and removal
28 Several useful PEAR kits
● HTML class – HTML_QuickForm – HTML_Table – Pager ● XML class – XML_RSS – XML_sql2xml – XML_Tree ● Mail – Mail – Mail_Queue
● PHP class – PHPUnit – PhpDocumentor ● Services – Services_Delicious – Services_Yahoo
29MySQL4.1
● MySQL 4.1 will be preset for Linux Dist in the near future ● Advantages of MySQL 4.1 – Support Sub Select – More complete multi lingual support – Faster ● MySQL has Query Cache function since 4. x ● What is the difference between MySQL 4.1 and MySQL 4.1? – Trigger – Stored Procedures
30MySQL Subqueries
● MySQL 4.1 has no Subqueries before ● Subqueries benefits – SQL syntax is more concise – More ways to query ● Please don't hesitate to use this convenient function! ● Official documents
– //dev.mysql.com/doc/mysql/en/subqueri es.html
31 What about Trigger and Stored Procedures?
● MySQL 4. x has no Trigger and Stored Procedures ● Trigger will be supported in MySQL 5 ● Stored Procedures will not be supported until MySQL 5 – However, MySQL 5 is still in the beta stage – But some websites have been used
32 Make MySQL Faster
● Don't forget to adjust your my.cnf – /etc/my.cnf – Please refer to the example under/usr/share/mysql ● Don't waste query_cache ● Use EXPLAIN to analyze your SQL syntax
33 FAQs when updating to MySQL 4.1
● Why are my data captured ● Why are all the garbled codes in phpMyAdmin2. 6 ● Why are all databases using myqldump garbled
34 Everything is a disaster caused by the support of multi lingual systems
● Database and client codes need to be set after 4.1 – Set the default language of the database ● /etc/my.cnf – [mysqld] – default-character-set=utf8 – character-set-server = utf8 – collation-server = utf8_general_ci ● If the system runs utf8 – init_connect='SET NAMES utf8′ – default-character-set = utf8 – default-collation = utf8_general_ci – Please set the client code after PHP connects to MySQL ● Send 'set names utf8' after database connection – $db->Execute('SET NAMES utf8'); – mysql_query('SET NAMES utf8');
Do you have to use UTF8?
● UTF8 is not necessary ● Database or data table code designation ● Database – CREATE DATABASE `MyTABLE` DEFAULT CHARACTER SET big5 COLLATE big5_chinese_ci; ● Data sheet – CREATE TABLE `myTable` ( – ..... etc .... – ) ENGINE=MyISAM DEFAULT CHARSET=big5 ; ● Try to make the server and client use the same Char – If different Character MySQL will try to help the conversion – For example, the same set of database data (utf8) – Clients of big5 and gb2312 are provided at the same time ● However, some conversions will fail, so there will be such problems as missing words or?? Generation 36
Export and import language system settings
● Most people will use mysqldump to backup data – Before MySQL 4.1, you could not specify a language family – You must specify a language family in mysql4.1 – mysqldump -u root -p --default-character-set=big5 my Table ● Re import data – Please also add language family settings
– mysql --default-character-set=big5 -u root -p < myTa ble.sql
37 Website and Reference Articles (1)
● PHP – //www.php.net ● Smarty – //smarty.php.net – Smarty-Lite
● //www.paullockaby.com/projects/smarty-lig ht/ ● PEAR – //pear.php.net ● TBS – TinyButStrong – //www.tinybutstrong.com
38 Website and Reference Articles (2)
● ADOdb – //adodb.sf.net – ADOdb-lite ● //adodblite.sf.net/ ● MySQL – //www.mysql.com ● Chinese reference website – //www.twpug.net – //www.php5.idv.tw
39PHP Command line scripting
● If you haven't learned how to write Shell Script ● If you are like me, you are basically familiar with PHP
● Maybe you can consider writing Command line scripting in PHP
40PHP Command line scripting
● What you need – Executable PHP execution file ● For example, Mandriva is a package that provides php cli – And you need to know where the executive file is located ● Mandriva in/usr/bin/php ● How? – Just like web applications ● Syntax, available functions and output are the same
41PHP Command line scripting
● How? – Execute directly [shell #] PHP ScriptFileName – Add # at the beginning of the file/ usr/bin/php -q ● Keep chmod+x files ● What else should I pay attention to? – Path of the include during execution ● It is recommended that such files use the absolute path include ● Especially when the script is to be put into crontab – The output of the program may need to remove html
42 How to go further?
● Framework learning ● Purpose of the Framework – Simplify the development process – Accelerate efficiency – Focus on the logic of the program, not on technical issues. ● Disadvantages of Framework – Learning curve is too long – Beginners learn the Framework and easily ignore basic technologies
43 Several recommended frameworks
● CakePHP – Refer to Ruby on Rails – Lighter than other framewords ● php. MVC – Refer to Java Struts ● Currently, Leduo blog (Blog. yam. com) is used ● Seagull – Using the PEAR library ● PRADO – Zend's award-winning work, event driven model – Only PHP5 This article was published by Beijing Website Construction Company Shangpin China //ihucc.com/
Source Statement: This article is original or edited by Shangpin China's editors. If it needs to be reproduced, please indicate that it is from Shangpin China. The above contents (including pictures and words) are from the Internet. If there is any infringement, please contact us in time (010-60259772).