Home > Article > Backend Development > PHP+MySQL basic knowledge supplement_PHP tutorial
1. 10 sentences
1. Don’t rely on the register_global=ON environment. From the day you first know how to configure the PHP operating environment and don’t even understand how register_global’s ON/OFF will affect you, you should bravely set it to OFF.
2. Before writing a program, look at how to use error_reporting.
3. It’s okay to ask yourself if you don’t understand, but you need to check the manual before that.
4. Of course, you need to understand the user manual. When you can't find the answer in the manual, you should consider searching on the Internet.
5. After you have just learned php+mysql, don’t clamor to write a forum, write XXX. Understand that just because you have just learned 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 your friend html.
7. After you have some ability, try to answer questions from novices. Don’t be complacent when you see that you understand something but others don’t. It’s even worse to leave without saying, “It’s simple, that’s a basic thing.”
8. Thinking is a good habit. If you don’t write, it means you have nothing.
9. After writing a program, if you feel satisfied with it, read it again after a week. Maybe you will think it should be changed
10. Take a look at other people’s programs when you have time, find out other people’s shortcomings or advantages, and weigh them yourself.
2. Everyone gets what they need
1. Be good at using "references", which can directly affect the efficiency of the program.
2. Being good at using ternary operators can make the program more streamlined and efficient.
For example:
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...loops
For example:
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();
}
}
You should write the above code 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 make your code as clear as possible. If it is written like this, it will be a headache:
PHP code:
$foo=$_post["foo"];
$username=$_post["user"];
$group=$_POST["group"];
if ($group=="wheel")
{
$username=$username."wheel";
}
The same code, so it is more comfortable to read:
PHP code:
$foo = $_post["foo"];
$username = $_post["username"];
$group = $_POST["group"];
if ($group=="wheel")
{
$username = $username."wheel";
}
Of course, after you have a certain foundation, you should write like this:
PHP code:
$foo = &$_POST[foo];
$username = $_POST["group"]!=wheel ? $_POST["username"] : $_POST["username"].wheel;
5. Write standardized mysql statements.
Field and table names are quoted with "`" to avoid the impact of reserved words.
If you see a SQL query like the following, it will give you 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` 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`";
The same query is much clearer when written like this:
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` 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`";