網頁

2014年12月23日 星期二

Sybase學習筆記-查詢table schema

在sybase中,看來不是用describe table來查table的schema設定,google半天看起來是用三個system table來查詢。

主要是用到sysobjects、syscolumns及systypes。

sysobjects主要是記錄有哪些被建立的物件,也包含Talbe,type如下(取自From a Sybase Database, how I can get table description ( field names and types)?):

  • C – computed column
  • D – default
  • F – SQLJ function
  • L – log
  • N – partition condition
  • P – Transact-SQL or SQLJ procedure
  • PR – prepare objects (created by Dynamic SQL)
  • R – rule
  • RI – referential constraint
  • S – system table
  • TR – trigger
  • U – user table
  • V – view
  • XP – extended stored procedure

所以使用下列的sql,就可以查到帳號可以存取的table
SELECT * FROM sysobjects WHERE type = 'U'

而我想查詢的是table中的column的type,所以要合用sysobjects、syscolumns及systypes,如下我要查的是Db_subject
select st.name, sc.name, sc.length from syscolumns sc 
inner join sysobjects so on sc.id = so.id 
inner join systypes st on st.type = sc.type 
where so.name = 'Db_subject'

這樣就可以看到Table的欄位資料了。

=============2015/04/07 更新==================

底下SQL可以更準確的取得

select o.name tableName,'' tableChnName,c.name columnName, '' columnChnName, t.name columnType,
(
case when (t.name='numeric' or t.name='decimal')
then '('+CONVERT(VARCHAR(10),c.prec)+','+CONVERT(VARCHAR(10),c.scale)+')'
else CONVERT(VARCHAR,c.length)
end
) columnLength --如果是數字,則顯示 (precision,scale)
from sysobjects o
inner join syscolumns c on c.id = o.id
inner join systypes t on t.usertype = c.usertype
where o.type = 'U' and o.name in ('表格1名稱', '表格2名稱' );

=======================================

參考網址:
From a Sybase Database, how I can get table description ( field names and types)?

2014年12月22日 星期一

CentOS筆記-CentOS 6.5 安裝MySQL 5.5

CentOS內定的yum server連結的是mysql 5.1,若要改用mysql 5.5則要先取得新的server。安裝步驟如下:

Cent OS 6.X使用底下指令
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Cent OS 5.X使用底下指令
rpm -Uvh https://mirror.webtatic.com/yum/el5/latest.rpm

若是安裝過舊mysql server
yum remove mysql mysql-*
#rpm -q mysql mysql-server //這個也行

----------------------------------
執行底下指令,會先安裝舊版再用5.5取代掉
yum install mysql.`uname -i` yum-plugin-replace
yum replace mysql --replace-with mysql55w
----------------------------------

再來執行安裝及設定安全性
yum install mysql55w mysql55w-server
service mysqld start
/usr/bin/mysql_secure_installation

完成!

參考網址:
MySQL 5.5 on CentOS/RHEL 6.5 and 5.10 via Yum
新安裝 CentOS 6.5 筆記

2014年12月14日 星期日

PHPUnit學習筆記-Broken PHP Configuration on Mavericks or later

之前裝好的PHPUnit後一直沒用,這陣子重新用時,卻發現一直出現底下的訊息
Warning: require(/usr/lib/php/pear/PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 43

Fatal error: require(): Failed opening required '/usr/lib/php/pear/PHPUnit/Autoload.php' (include_path='.:') in /usr/bin/phpunit on line 43

想不透原因是什麼,查到了Broken PHP Configuration on OSX Mavericks這篇,試了下底下的command
$sudo pear -V
//也可以用pear config-get php_dir

output底下的訊息
Could not open input file: /usr/lib/php/pear/pearcmd.php

看來PEAR真的消失了,參考自己之前寫的PHPUnit學習筆記-PHPUnit安裝(使用PEAR),重新安裝一次
$sudo cp /private/etc/php.ini.default /private/etc/php.ini
$sudo php /usr/lib/php/install-pear-nozlib.phar 
$sudo pear config-set php_ini /private/etc/php.ini
$sudo pear channel-update pear.php.net
$sudo pecl channel-update pecl.php.net
$sudo pecl config-set php_ini /private/etc/php.ini
$sudo pear upgrade-all
$sudo vim /private/etc/php.ini

再執行pear -V,發現PEAR ok了,但是執行底下的command,依然同樣的error
$phpunit -v

重新安裝PHPUnit
$sudo pear config-set auto_discover 1
//sudo pear channel-discover
$sudo pear channel-discover pear.phpunit.de
$sudo pear channel-discover components.ez.no
$sudo pear channel-discover pear.symfony-project.com 
$sudo pear channel-discover pear.symfony.com 
$sudo pear install --alldeps phpunit/PHPUnit

再次執行
$phpunit -v

但這次卻一直出現以下的訊息
You have installed PHPUnit via PEAR. This installation method is no longer
supported and http://pear.phpunit.de/ will be shut down no later than
December, 31 2014.

Please read http://phpunit.de/manual/current/en/installation.html and
learn how to use PHPUnit from a PHAR or install it via Composer.

執行底下command,看看裝了什麼
$pear list -c pear.phpunit.de
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
PHPUnit 4.0.18  stable

看起來很正常,但就是不能用,只好咬牙改用Composer的方式安裝了,找到這篇寫的完整的Installing PHPUnit(官網:Composer安裝Composer

先Uninstall
$sudo pear uninstall phpunit/PHPUnit
$cd /tmp (先換到tmp目錄)
$curl -sS https://getcomposer.org/installer | php

得到以下訊息
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /private/tmp/composer.phar
Use it: php composer.phar

copy composer.phar去/usr/local/bin
$cp composer.phar /usr/local/bin
$php /usr/local/bin/composer.phar global require "phpunit/phpunit=4.3.*"


安裝完後,到~/.composer/vendor下,要能看到phpunit安裝在這裡
autoload.php composer phpunit  symfony
bin  doctrine sebastian

再來做個link
$cd /usr/bin
$sudo ln -s sudo ln -s /Users/alvin/.composer/vendor/phpunit/phpunit/phpunit phpunit
$phpunit --version

得到底下訊息,可以執行了
PHPUnit 4.3.5 by Sebastian Bergmann.

參考網址:
Broken PHP Configuration on OSX Mavericks
PHPUnit on OSX10.8
Installing PHPUnit
How to remove a package from composer?
composer document
Composer

2014年12月13日 星期六

MSSQL server學習筆記-取得中文檔名的欄位名

需求:
  • DB Server: MSSQL
  • 欄位使用中文
  • 要能正確讀取
一般來講Table欄位都是英文,但國內用MSSQL的公家機關大多用中文,為了省麻煩,乾脆想想怎弄,可以猜出是chart set問題而已,Windows系統在國內大多Big 5編碼,而MSSQL通常安裝時都是直接用預設,所以朝這方向處理

程式碼如下,做個編碼轉換即可用這個當key去取值了
function get_mssql_chinese_col_name($ch_name)
{
    return mb_convert_encoding($ch_name, 'big5', 'utf8');
}

蠻特別的是,Table name不會有這問題,我想是SQL上的使用是沒差的,但取值出來放在array中時,欄位名放在php array中的key在使用,就會有差別

Mac學習筆記-開啟HTTPS


[1] 產生 host key
$sudo mkdir /private/etc/apache2/ssl
$cd /private/etc/apache2/ssl
$sudo ssh-keygen -f host.key

[2] 產生certificate request file
sudo openssl req -new -key host.key -out request.csr

[3] 產生certificate request file
$sudo openssl req -new -key host.key -out request.csr

[4] 加入產生的SSL certificate及‘nopass’ key
$sudo openssl x509 -req -days 365 -in request.csr -signkey host.key -out server.crt
openssl rsa -in host.key -out host.nopass.key

找到SSLCertificateFile及SSLCertificateKeyFile,更改file位置
#SSLCertificateFile "/private/etc/apache2/server.crt"
SSLCertificateFile "/private/etc/apache2/ssl/server.crt"
#SSLCertificateKeyFile "/private/etc/apache2/server.key"
SSLCertificateKeyFile "/private/etc/apache2/ssl/host.nopass.key"

[5] 確認Apache有加入ssl_module
$sudo vim httpd.conf

找出底下兩個,將"#"刪除或加入
LoadModule ssl_module libexec/apache2/mod_ssl.so
Include /private/etc/apache2/extra/httpd-ssl.conf

[OS X 10.10的Apache 2.4] 預設不載入shmcb,要找出底下的將"#"刪除
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so

[6] 做測試
apachectl configtest

[OS X 10.10的Apache 2.4] 會出現底下訊息
AH00526: Syntax error on line 62 of /private/etc/apache2/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).
$sudo vim /private/etc/apache2/extra/httpd-ssl.conf

將找到SSLMutex將其註解並加上Mutex
#SSLMutex  "file:/private/var/run/ssl_mutex"
Mutex sysvsem default

[7] 確認回傳Syntax OK,啟動Server
apachectl restart


參考網址:
APACHE SSL ON MAC OSX LION 10.7
CREATING A SELF-SIGNED SSL CERT FOR MAC OSX MOUNTAIN LION & APACHE
How To: Set up SSL with OSX Mountain Lion’s built-in Apache
How to create self signed ssl certificate for apache2 web server
SSH 免密碼登入

For OS X 10.10 Yosemite
Apache 2.4 configuration for ssl not working

2014年12月12日 星期五

Wordpress開發筆記-PHP Warning: Cannot modify header information for wp-session.php on line 124

wp session這個plugin真的是蠻好用的,不過使用時一直有類似log出現

[Fri Nov 21 11:55:06 2014] [error] [client ::1] PHP Warning:  Cannot modify header information - headers already sent by (output started at /work/demo/wp-admin/menu-header.php:118) in /work/demo/inc/lib/wp-session-manager/class-wp-session.php on line 124, referer: https://localhost/~alvin/demo/wp-admin/edit.php?post_type=exercise

這個warning猜測是因為正常處理下,最後會執行到wp_session_commit(),但若是用ajax的方式時,或直接用die()結束時,並沒有執行wp_session_commit(),以至於有這個warning,最後實驗結果,果然如我所料,哈哈


參考網址: