Home Database Mysql Tutorial PHP+MYSQL网站开发基础知识_MySQL

PHP+MYSQL网站开发基础知识_MySQL

Jun 01, 2016 pm 01:57 PM
basic knowledge Influence Operating environment

    一. 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代码:

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();
  }
}
  上面的代码你应该写成这样:

  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”;
}

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

  PHP代码:

$foo   = &$_POST[’foo’];
$username = $_POST[”group”]!=’wheel’ ? $_POST[”username”] : $_POST[”username”].’wheel’;

  5.编写规范的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`”;

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error Mar 24, 2024 am 09:51 AM

When trying to open a disk image in VirtualBox, you may encounter an error indicating that the hard drive cannot be registered. This usually happens when the VM disk image file you are trying to open has the same UUID as another virtual disk image file. In this case, VirtualBox displays error code VBOX_E_OBJECT_NOT_FOUND(0x80bb0001). If you encounter this error, don’t worry, there are some solutions you can try. First, you can try using VirtualBox's command line tools to change the UUID of the disk image file, which will avoid conflicts. You can run the command `VBoxManageinternal

How effective is receiving phone calls using airplane mode? How effective is receiving phone calls using airplane mode? Feb 20, 2024 am 10:07 AM

What happens when someone calls in airplane mode? Mobile phones have become one of the indispensable tools in people's lives. It is not only a communication tool, but also a collection of entertainment, learning, work and other functions. With the continuous upgrading and improvement of mobile phone functions, people are becoming more and more dependent on mobile phones. With the advent of airplane mode, people can use their phones more conveniently during flights. However, some people are worried about what impact other people's calls in airplane mode will have on the mobile phone or the user? This article will analyze and discuss from several aspects. first

How to turn off the comment function on TikTok? What happens after turning off the comment function on TikTok? How to turn off the comment function on TikTok? What happens after turning off the comment function on TikTok? Mar 23, 2024 pm 06:20 PM

On the Douyin platform, users can not only share their life moments, but also interact with other users. Sometimes the comment function may cause some unpleasant experiences, such as online violence, malicious comments, etc. So, how to turn off the comment function of TikTok? 1. How to turn off the comment function of Douyin? 1. Log in to Douyin APP and enter your personal homepage. 2. Click "I" in the lower right corner to enter the settings menu. 3. In the settings menu, find "Privacy Settings". 4. Click "Privacy Settings" to enter the privacy settings interface. 5. In the privacy settings interface, find "Comment Settings". 6. Click "Comment Settings" to enter the comment setting interface. 7. In the comment settings interface, find the "Close Comments" option. 8. Click the "Close Comments" option to confirm closing comments.

File Inclusion Vulnerabilities in Java and Their Impact File Inclusion Vulnerabilities in Java and Their Impact Aug 08, 2023 am 10:30 AM

Java is a commonly used programming language used to develop various applications. However, just like other programming languages, Java has security vulnerabilities and risks. One of the common vulnerabilities is the file inclusion vulnerability (FileInclusionVulnerability). This article will explore the principle, impact and how to prevent this vulnerability. File inclusion vulnerabilities refer to the dynamic introduction or inclusion of other files in the program, but the introduced files are not fully verified and protected, thus

The impact of data scarcity on model training The impact of data scarcity on model training Oct 08, 2023 pm 06:17 PM

The impact of data scarcity on model training requires specific code examples. In the fields of machine learning and artificial intelligence, data is one of the core elements for training models. However, a problem we often face in reality is data scarcity. Data scarcity refers to the insufficient amount of training data or the lack of annotated data. In this case, it will have a certain impact on model training. The problem of data scarcity is mainly reflected in the following aspects: Overfitting: When the amount of training data is insufficient, the model is prone to overfitting. Overfitting refers to the model over-adapting to the training data.

What problems will bad sectors on the hard drive cause? What problems will bad sectors on the hard drive cause? Feb 18, 2024 am 10:07 AM

Bad sectors on a hard disk refer to a physical failure of the hard disk, that is, the storage unit on the hard disk cannot read or write data normally. The impact of bad sectors on the hard drive is very significant, and it may lead to data loss, system crash, and reduced hard drive performance. This article will introduce in detail the impact of hard drive bad sectors and related solutions. First, bad sectors on the hard drive may lead to data loss. When a sector in a hard disk has bad sectors, the data on that sector cannot be read, causing the file to become corrupted or inaccessible. This situation is especially serious if important files are stored in the sector where the bad sectors are located.

What are the php operating environments? What are the php operating environments? Jul 12, 2023 pm 01:47 PM

The PHP operating environment includes: 1. Web server; 2. PHP interpreter; 3. PHP extension module; 4. Database; 5. Development tools and integrated development environment (IDE); 6. Resource manager and dependency manager; 7. debugger.

What specific impact do mine cards have on the game? What specific impact do mine cards have on the game? Jan 03, 2024 am 09:05 AM

Some users may consider buying mining cards for the sake of cheapness. After all, these cards are top-notch graphics cards. However, some gamers are worried about the impact of mining cards on playing games. Let’s take a look at the detailed introduction below. What are the effects of using a mining card to play games: 1. The stability of playing games with a mining card cannot be guaranteed, because the life of the mining card is very short and it is likely to become useless after just playing. 2. The mining card is basically a castrated version of the original version. Due to long-term wear and tear, the performance in all aspects may be weak. 3. In this way, users may not be able to display all the effects of the game when playing the game. 4. Moreover, the electronic components of the graphics card will age in advance, not to mention that playing games also consumes the graphics card, so it is drained to a greater extent, so the impact on the game is great. 5. In general, use mining cards to play games

See all articles