1、通过域名取得网站ip地址 gethostbyname('域名'); 如gethostbyname('www.baidu.com');返回ip地址
ip2long('ip地址')? 将ip地址转为long数据类型
long2ip('long类型') 将long类型转换为ip地址
?
2、将一张表的数据复制到另外一张表中(两张表的结构必须一致)
insert into user_new(t_name,sex) select t_name,sex from user_old
?
3、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('张映', 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、优化limit和offset
mysql的limit工作原理就是先读取n条记录,然后抛弃前n条,读m条想要的,所以n越大,性能会越差。
优化前sql: select * from member order by last_active limit 50,5
优化后sql: select * from zb_sms_sendsmslog inner join (select id from zb_sms_sendsmslog order by id limit 100000,100) as tmp using(id)
分别在于,优化前的sql需要更多i/o浪费,因为先读索引,再读数据,然后抛弃无需的行。而优化后的sql(子查询那条)只读索引(cover index)就可以了,然后通过member_id读取需要的列。
?
5、post提交表单后的内容中的双引号全部都自动在前面被加上了反斜杠
$b_str = $_post[$b_controlname]; if (get_magic_quotes_gpc()) { $b_str = stripslashes($b_str); }
?
6、php使用gbk编码时,参数中带有特殊中文字符如(咯
在执行sql前先执行
set character_set_connection=gbk, character_set_results=gbk,character_set_client=binary
?
?
?7、smarty模板中定义变量
. title:
author:
isbn:
price:
?
8、smarty中使用类似for循环
用一段section模拟
{section name=loop loop=$count}
id: {$smarty.section.loop.index}
{/section}
给count赋个值
$smarty->assign('count', 5);
