PHP commonly used sorting 1. get the website IP address gethostbyname (domain name) through the domain name );?? For example, gethostbyname (www.baidu.com); IP address ip2long (IP address )? Convert an IP address to a long data type long2ip (long type )?? Convert long type to IP address? 2. copy the data in one table to another table.
1. get the website IP address gethostbyname ('domain name') through the domain name ');?? For example, gethostbyname ('www .baidu.com '); IP address returned
Ip2long ('IP address ')? Convert an IP address to a long data type
Long2ip ('long type ')?? Convert long type to IP address
?
2. copy data from one table to another (the two tables must have the same structure)
Insert into user_new (t_name, sex) SELECT t_name, sex FROM user_Old
?
3. create a table in mysql
Mysql> create table if not exists 'user1' (-> 'id' int (11) not null AUTO_INCREMENT,-> 'name' varchar (50) default null, -> 'sex' int (1) not null default '0',-> primary key ('id')->) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1; query OK, 0 rows affected (0.05 sec) mysql> CREATE TABLE IF NOT EXISTS 'user2' (-> 'id' int (11) NOT NULL AUTO_INCREMENT, -> 'name' varchar (50) default null,-> 'sex' int (1) not null default '0',-> primary key ('id')->) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1; Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO 'user1' ('name', 'sex ') VALUES ('Zhang Ying', 0); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO 'user2' ('name', 'sex ') VALUES ('tank', 1); Query OK, 1 row affected (0.00 sec) mysql> CREATE TABLE IF NOT EXISTS 'alluser' (-> 'id' int (11) not null AUTO_INCREMENT,-> 'name' varchar (50) default null,-> 'sex' int (1) not null default '0',-> INDEX (id) ->) TYPE = MRG_MyISAM UNION = (user1, user2) INSERT_METHOD = LAST AUTO_INCREMENT = 1; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> select id, name, sex from alluser; + ---- + -------- + ----- + | id | name | sex | + ---- + -------- + ----- + | 1 | | 0 | 1 | tank | 1 | + ---- + -------- + ----- + 2 rows in set (0.00 sec) mysql> insert into 'alluser' ('name', 'sex') VALUES ('tank2', 0); Query OK, 1 row affected (0.00 sec) mysql> select id, name, sex from user2->; + ---- + ------- + ----- + | id | name | sex | + ---- + ------- + ----- + | 1 | tank | 1 | 2 | tank2 | 0 | + ---- + ------- + ----- + 2 rows in set (0.00 sec)
?
?
4,Optimize limit and offset
MySQL's limit mechanism is to read n records first, then discard the first n records and read m records. Therefore, the larger n records, the worse the performance.
SQL before optimization: SELECT * FROM member ORDER BY last_active LIMIT 50, 5
After optimization, SQL: select * from zb_sms_sendsmslog inner join (select id from zb_sms_sendsmslog order by id limit 100000,100) as tmp using (id)
The difference is that the SQL statement before optimization requires more I/O waste, because the index is read first, data is read again, and unnecessary rows are discarded. After optimization, the read-only index (Cover index) of the SQL statement (subquery) can be used to read the required columns through member_id.
?
5. POSTSubmit formInDouble quotation marksAllAutomaticIn frontA backslash is added.
$ B _Str = $ _ POST [$ B _ControlName]; if (get_magic_quotes_gpc () {$ B _Str = stripslashes ($ B _Str );}
?
6. When Php uses GBK encoding, the parameter contains special Chinese characters, such
Run the SQL statement first.
SET character_set_connection = GBK, character_set_results = GBK, character_set_client = binary
?
?
? 7. variables defined in the Smarty Template
<{Assign var = "I" value = 0 }> <{section name = book loop = $ books}>
<{$ I = $ I + 1}> <{$ I}>. Title: <{$ books [book]. title}>
Author: <{$ books [book]. author}>
ISBN: <{$ books [book]. isbn}>
Price: <{$ books [book]. price}>
<{/Section}>
?
8. Use a for loop similar
Simulate using a section
{Section name = loop = $ count}
Id: {$ smarty. section. loop. index}
{/Section}
Assign count values
$ Smarty-> assign ('count', 5 );