2011-12-18

[MySQL] char vs. varchar


可用長度:
char 0 ~ 255
varchar 0 ~ 65535

儲存資料長度:
char 為建立 table 時所決定的長度
varchar 依你所存放的資料而定,直到你決定的最大長度


char

char 在實際儲存資料時,在右邊補滿空白

name CHAR(5)

  ---------------------------------------
    value      actual_storage   Space
  ---------------------------------------
    'ex'       'ex   '          5 bytes
    'exper'    'exper'          5 bytes
    'expert'   'exper'          5 bytes
  ---------------------------------------

varchar

varchar 不填補空白,而是在額外用 1 到 2 byte 去記錄
長度在 255 內用 1 byte,超過 255 就用到 2 byte

name VARCHAR(5)

  ---------------------------------------
    value      actual_storage   Space
  ---------------------------------------
    'ex'       'ex'             3 bytes
    'expe'     'expe'           5 bytes
    'expert'   'exper'          6 bytes
  ---------------------------------------


Reference:
CHAR vs VARCHAR in MySQL
Tsung's Blog - MySQL 欄位格式 CHAR 與 VARCHAR 的差異

2011-11-16

Magical Methods in PHP Class

Named starting with __ as magical

__construct()
will be called on each newly-created object

__destruct()
will be called there are no other references to a particular object in any order during the shutdown sequence.

__isset()
is triggered by calling isset() or empty() on inaccessible properties.

__unset()
is invoked when unset() is used on inaccessible properties.

__set()
is run when writing data to inaccessible properties.

__get()
is utilized for reading data from inaccessible properties.

__call()
is triggered when invoking inaccessible methods in an object context.

__callStatic()
is triggered when invoking inaccessible methods in a static context.

__sleep()
serialize() checks __sleep().
executed prior to any serialization.

__wakeup()
unserialize() checks __wakeup().
this function can reconstruct any resources that the object may have.

__toString()
when it is treated like a string. must return a string

__invoke()
call an object as a function.

__set_state()
be called for classes exported by var_export()

__clone()
Once the cloning is complete,
if a __clone() method is defined,
then the newly created object's __clone() method will be called

Reference:

http://php.net/manual/en/language.oop5.magic.php 石頭閒語 - http://blog.roodo.com/rocksaying/archives/10796767.html
石頭閒語 - http://blog.roodo.com/rocksaying/archives/2683180.html

[PHP] Equal vs. Identical

Equal: ==
Identical: ===
兩個都是用來進行比較運算的 "Comparison Operators"
有什麼不一樣呢?

如果是要比較不同的資料型態時,
使用 "Equal" 時,會先轉換成相同的資料型態,再進行比較
使用 "Identical" 時,不會轉換資料型態


Reference:
http://blog.roodo.com/rocksaying/archives/2565180.html
http://www.php.net/manual/en/language.operators.comparison.php
http://www.php.net/manual/en/types.comparisons.php

2011-10-30

GTK-Warning: pixmap

作業系統換上全新的 Ubuntu 11.10 ,遇到了一些問題
新出來的東西嘛,難免的

錯誤訊息:
Gtk-WARNING **: 無法在module_path 中找出佈景主題引擎:‘pixmap’

解決方案:
安裝缺少的套件就好了~
sudo apt-get install gtk2-engines-pixbuf

Reference:
Tsung's Blog - Ubuntu 修復 GTK WARNING(module_path, pixmap)

2011-10-03

ID3 Tag - 轉換編碼

在 Linux 上要播 MP3 時,常常會看到音樂的相關資訊變成亂碼,
這是因為 MP3 裡的 ID3 tags 編碼不是 UTF-8。

要解決這個問題不難,有個工具可以輕鬆的轉換編碼,就是 mid3iconv

安裝

只要安裝 python-mutagen 套件,就可以有好用的 mid3iconv 可以用了
$ sudo apt-get install python-mutagen

操作方法

裝好之後就可以開始轉換了。

如果確定要轉換編碼的 ID3 Tag 原本是 big5 的話,
就用以下指令轉換當前資料夾裡的所有 MP3 的 ID3 編碼
$ mid3iconv -e big5 *.mp3 參數
-e 編碼
    資料原本的編碼
-p, --dry-run
    不會改變原檔案

更進階的用法:
轉換目前目錄下所有子目錄的 MP3
find . -iname "*.mp3" -execdir mid3iconv -e big5 {} \;
Ubuntu Linux - 用mid3iconv及exfalso批次整理舊MP3的ID3標籤
[筆記]在Ubuntu下大量轉換ID3之編碼