Home php教程 php手册 php+mysql扎实个人基本功

php+mysql扎实个人基本功

Jun 13, 2016 am 10:21 AM
global php+mysql one personal rely environment of

一. 10句话
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.善于用三元运算子,可以让程式较精简有效率。
比如:

PHP代码:<hr>

<br>if ($data[$i][nickname])

<br>{

<br>    $nickname =  $data[$i][nickname];

<br>}

<br>else

<br>{

<br>    $nickname =  $data[$i][ip];

<br>}<br>



<hr>
Copy after login


可以写成:

PHP代码:<hr>

<br>$nickname =  $data[$i][nickname] ? $data[$i][nickname] : $data[$i][ip];<br>



<hr>
Copy after login



3.善于组织if...else...回圈
比如:

PHP代码:<hr>

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

<br>if (!empty($type))

<br>{

<br>    if (!strpos($type, $ext_name))

<br>    {

<br>        echo "Please upload the file of $type form.";

<br>        exit();

<br>    }

<br>}<br>



<hr>
Copy after login


上面的代码你应该写成这样:

PHP代码:<hr>

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

<br>if (!($type===) && strpos($type, $ext_name)===false)

<br>{

<br>    echo "Please upload the file of $type form.";

<br>    exit();

<br>}<br>



<hr>
Copy after login



4.尽量让你的代码清淅些
如果写成这样,是比较让人头痛的:

PHP代码:<hr>

<br>$foo=$_post["foo"];

<br>   $username=$_post["user"]; 

<br>$group=$_POST["group"];

<br>if ($group=="wheel"){

<br>$username=$username."wheel";

<br>}<br>



<hr>
Copy after login


同样的代码,这样就比较让人看得舒服了:

PHP代码:<hr>

<br>$foo      = $_post["foo"];

<br>$username = $_post["username"];

<br>$group    = $_POST["group"];

<br>if ($group=="wheel")

<br>{

<br>    $username = $username."wheel";

<br>}<br>



<hr>
Copy after login


当然,有一定基础后,你应该要写成这样:

PHP代码:<hr>

<br>$foo      = &$_POST[foo];

<br>$username =  $_POST["group"]!=wheel ? $_POST["username"] : $_POST["username"].wheel;<br>



<hr>
Copy after login


5.编写规范的mysql 语句。
字段和表名用"`"引起来,避免保留字的影响。
如果看到下面这样的一个sql query,会让人比较头痛:

PHP代码:<hr>

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



<hr>
Copy after login


同样的一个query,写成这样就令人看得明白得多了:

PHP代码:<hr>

<br>$query = "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`";<br>
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to boot into Windows recovery environment Unable to boot into Windows recovery environment Feb 19, 2024 pm 11:12 PM

Windows Recovery Environment (WinRE) is an environment used to repair Windows operating system errors. After entering WinRE, you can perform system restore, factory reset, uninstall updates, etc. If you are unable to boot into WinRE, this article will guide you through fixes to resolve the issue. Unable to boot into the Windows Recovery Environment If you cannot boot into the Windows Recovery Environment, use the fixes provided below: Check the status of the Windows Recovery Environment Use other methods to enter the Windows Recovery Environment Did you accidentally delete the Windows Recovery Partition? Perform an in-place upgrade or clean installation of Windows below, we have explained all these fixes in detail. 1] Check Wi

What are the differences between Python and Anaconda? What are the differences between Python and Anaconda? Sep 06, 2023 pm 08:37 PM

In this article, we will learn about the differences between Python and Anaconda. What is Python? Python is an open source language that places great emphasis on making the code easy to read and understand by indenting lines and providing whitespace. Python's flexibility and ease of use make it ideal for a variety of applications, including but not limited to scientific computing, artificial intelligence, and data science, as well as creating and developing online applications. When Python is tested, it is immediately translated into machine language because it is an interpreted language. Some languages, such as C++, require compilation to be understood. Proficiency in Python is an important advantage because it is very easy to understand, develop, execute and read. This makes Python

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) Dec 31, 2023 pm 05:15 PM

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

The first choice for CS players: recommended computer configuration The first choice for CS players: recommended computer configuration Jan 02, 2024 pm 04:26 PM

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

Introduction to methods for individuals to join corporate WeChat Introduction to methods for individuals to join corporate WeChat Mar 26, 2024 am 10:16 AM

1. First, open the enterprise WeChat software you downloaded on your mobile phone. When logging in, there are two ways to choose: one is to use WeChat ID, the other is to use mobile phone number. 3. At this time, the enterprise administrator needs to add your mobile phone number in the background, and then Enterprise WeChat will identify the enterprise based on your mobile phone number. Then display your business and click the Enter Business option below. 4. Then you can enter the use of functions in the software. It can be said that the most important thing is that your mobile phone number must be added to the enterprise by the administrator, otherwise it will not be available.

Glodon Software's computer configuration recommendations; Glodon Software's computer configuration requirements Glodon Software's computer configuration recommendations; Glodon Software's computer configuration requirements Jan 01, 2024 pm 12:52 PM

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing

Digital audio output interface on the motherboard-SPDIF OUT Digital audio output interface on the motherboard-SPDIF OUT Jan 14, 2024 pm 04:42 PM

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

CentOS installation gnuplot and CentOS installation sunflower are missing dependencies CentOS installation gnuplot and CentOS installation sunflower are missing dependencies Feb 13, 2024 pm 11:39 PM

LINUX is a widely used operating system that is highly customizable and stable. CentOS is a free and open source operating system built on the Red Hat Enterprise Linux (RHEL) source code. It is widely used in servers and desktop environments. In CentOS Installing software packages on CentOS is one of the common tasks in daily use. This article will introduce how to install gnuplot on CentOS and solve the problem of missing dependencies of Sunflower software. Gnuplot is a powerful drawing tool that can generate various types of charts, including two-dimensional and three-dimensional data visualization. To install gnuplot on CentOS, you can follow the steps below: 1.

See all articles