Opinion's experience php+mysql solid personal skills

Source: Internet
Author: User
Tags date exit manual join mysql php code query
Mysql

A. 10 words
1. Do not rely on register_global=on environment, from you just know how to configure PHP to run the environment not even understand Register_global On/off will have any impact on their own day, you should be brave to set it off.
2. See how to use error_reporting before writing a program.
3. It's right to ask if you don't know, but you need to check the manual before that.
4. Of course, you need to know how to use the manual. When the manual does not find the answer, you should consider the search engine on the web.
5. Just learn to Php+mysql, do not shout to write a forum, to write xxx. To understand that just learning to write Chinese characters does not mean that you are capable of writing poetry.
6. When learning Web programming, you should first get to know the HTML friend.
7. After a bit of ability, try to answer the novice question, do not see oneself understand and others do not understand complacent, throw down a "simple, that is the basic thing" to go more must not.
8. Thinking is a good habit, do not write is tantamount to fantasy, nothing.
9. Write a program, if you feel very satisfied, after a week to see again, perhaps you will think it should be changed
10. Have a free time to look at other people's procedures, find out the shortcomings or advantages of others, their own weigh.

Two. What to do

1. Good at using "references", it can directly affect the efficiency of the program.

2. Good at using ternary operators, you can make the program more streamlined and efficient.
Like what:

PHP Code:
  
   
if ($data [$i] [' nickname '])
{
$nickname = $data [$i] [' nickname '];
}
Else
{
$nickname = $data [$i] [' IP '];
}


Can be written as:

PHP Code:
  
   
$nickname = $data [$i] [' nickname ']? $data [$i] [' nickname ']: $data [$i] [' IP '];



3. Good at organizing if...else ... Back Circle
Like what:

PHP 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 ();
}
}


The code above should be written like this:

PHP 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. Try to keep your code clear.
If it's written like this, it's a bit of a headache:

PHP Code:
  
   
$foo =$_post["foo"];

$group =$_post["group"];
if ($group = = "Wheel") {
$username = $username. " Wheel ";
}


The same code, which is more comfortable to see:

PHP Code:
  
   
$foo = $_post["foo"];
$username = $_post["username"];
$group = $_post["group"];
if ($group = = "Wheel")
{
$username = $username. " Wheel ";
}


Of course, after a certain foundation, you should write this:

PHP Code:
  
   
$foo = &$_post[' foo '];
$username = $_post["group"]!= ' wheel '? $_post["username"]: $_post["username"]. ' Wheel ';


5. Write the specification of the MySQL statement.
Fields and table names are used "'" to avoid the effects of reserved words.
If you see a SQL query like this, you can get a headache:

PHP 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 ' (' flash_comment '. ' P_no ' = ' product '. ' P _no ') left Join ' Sgflash ' (' Product '. ' P_name ' = ' sgflash '. ' F_name ') where ' flash_comment '. ' P_no '!= ' ' ORDER BY ' FLA Sh_comment '. ' Date ';


The same query, written in this way, makes it much more clear:

PHP Code:
  
   




WHERE ' flash_comment '. ' P_no '!= '
ORDER BY ' flash_comment '. ' Date ';


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.