by kevin
11.
十一月 2014 21:10
>
chown命令: 可以用来改变linux文件的所有者,用到这个,是因为交替使用ftp和winscp上传文件,而且使用了不同的用户,导致经常出现上传失败。 css的 line-height: 很多浏览器默认line-height的值是font-size的120%,也有是100%的,所有应该考虑reset一下。 php的日期比较: 过程化方法:date_diff 对象化方法:DateTimeObject->diff 这个没有.net那么舒服,有个TimeSpan,要获取相差多少天,多少秒的,真心麻烦。 直接上代码: 1: public static function datediff($dt_menor, $dt_maior, $str_interval, $relative=false) {
2: if (is_string($dt_menor))
3: $dt_menor = date_create($dt_menor);
4: if (is_string($dt_maior))
5: $dt_maior = date_create($dt_maior);
6:
7: $diff = date_diff($dt_menor, $dt_maior, !$relative);
8:
9: switch ($str_interval) {
10: case "y":
11: $total = $diff->y + $diff->m / 12 + $diff->d / 365.25;
12: break;
13: case "m":
14: $total = $diff->y * 12 + $diff->m + $diff->d / 30 + $diff->h / 24;
15: break;
16: case "d":
17: $total = $diff->y * 365.25 + $diff->m * 30 + $diff->d + $diff->h / 24 + $diff->i / 60;
18: break;
19: case "h":
20: $total = ($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h + $diff->i / 60;
21: break;
22: case "i":
23: $total = (($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i + $diff->s / 60;
24: break;
25: case "s":
26: $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i) * 60 + $diff->s;
27: break;
28: }
29: if ($diff->invert)
30: return -1 * $total;
31: else
32: return $total;
33: }
by kevin
5.
十一月 2014 23:16
>
碰到一个恶心的问题: 无法保存包含中文的字符串,查了很久,就懂的是字符集的问题。 mysql的字符集在server,database,table,column都可以定义。 查看字符集: 数据库级别 1: SELECT default_character_set_name FROM information_schema.SCHEMATA S
2: WHERE schema_name = "schemaname";
表级别
1: SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
2: information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
3: WHERE CCSA.collation_name = T.table_collation
4: AND T.table_schema = "schemaname"
5: AND T.table_name = "tablename";
列级别
1: SELECT character_set_name FROM information_schema.`COLUMNS` C
2: WHERE table_schema = "schemaname"
3: AND table_name = "tablename"
4: AND column_name = "columnname";
修改数据库字符集:
1: ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...];
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
1: ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE ...]
只是修改表的默认字符集:
1: ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...];
修改列的字符集:
1: ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE ...];
by kevin
5.
十一月 2014 23:05
>
一些常用的函数: 返回对象的类名 string get_class ([ object $obj ] ) 获取变量的类型 string gettype ( mixed $var ) 检查类是否已定义 bool class_exists ( string $class_name [, bool $autoload = true ] ) 检查类的方法是否存在 bool method_exists ( mixed $object , string $method_name )
by kevin
5.
十一月 2014 22:49
>
日期格式化: 有两个函数:date(format,timestamp)和date_format(object,format) 共同点:都有format参数 差别在于: 1. 参数顺序 2. 参数类型date需要一个timestamp,而date_format需要一个DateTime实例。