leolo’s Blog


[CSS] a:link,a:visited,a:hover,a:active order


a:link {color: #FF0000}     /* unvisited link */
a:visited {color: #00FF00}  /* visited link */
a:hover {color: #FF00FF}   /* mouse over link */
a:active {color: #0000FF}   /* selected link */

Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!!
Note: a:active MUST come after a:hover in the CSS definition in order to be effective!!

PHP Shell Script

We can use php as a shell script by adding the line below at the top of the php script file.

#!/usr/local/bin/php -Cq

C means do not change working directory to that of the script.
q means do not send HTTP header.

There is a reference manual 『Using PHP from the command line』 in php.net


PHP中include和require的差異

PHP中include和require的差異在於找不到引入的檔案時,require會停止解譯php程式,include則不會。


在Oracle中找出重複的紀錄的方法

在Oracle中找出重複的紀錄的方法
SELECT aid FROM atable GROUP BY aid HAVING COUNT(*) >1;

刪除重複的記錄
DELETE FROM atable a where a.ROWID!=(SELECT MAX(ROWID) FROM atable b WHERE a.aid=b.aid;


在ORACLE/PLSQL裡使用游標FOR迴圈(cursor FOR loop)

藉由從abc_stu資料表內抓取該學號的生日,來更新stu資料表裡每個學號的生日。

DECLARE
CURSOR cur IS
SELECT stuid FROM stu;
BEGIN
FOR rec IN cur
LOOP
UPDATE stu
SET (birth_yr,birth_mm,birth_dd)=
(SELECT birth_yr,birth_mm,birth_dd FROM abc_stu WHERE stuid=rec.stuid)
WHERE stuid=rec.stuid;
END LOOP;
END;


Oracle/PLSQL: If Exists Update Else Insert

If data exists then update it, otherwise insert it.
In Oracle/PLSQL

BEGIN
UPDATE TABLE_NAME SET COL=’a’ WHERE ID=’foobar’;
IF sql%rowcount = 0 THEN
INSERT INTO TABLE_NAME (ID,COL) VALUES(‘foobar’,'a’);
END IF;
END;


some problem with PHP SESSION Array

session_test.php

<?php
session_start();
$_SESSION['IDNO']=’A1234′;
$_SESSION['DPT_COD'][0]=’1402′;
$_SESSION['DPT_COD'][1]=’B402′;
Print_r($_SESSION);
echo 『<br /><a href=』session_test2.php』>next!</a>』;
?>


The browser show:
Array ( [IDNO] => A1234 [DPT_COD] => Array ( [0] => 1402 [1] => B402 ) )
next!

session_test2.php

<?php
session_start();
echo 『Original SESSION array values:<br />』;
Print_r($_SESSION);
echo 『<br /><br />』;

echo 『New SESSION array values:<br />』;
$IDNO=’Z5678′;
$DPT_COD=’foobar’;
Print_r($_SESSION);

session_unset();
session_destroy();
?>

In machine 1
The browser show:
Original SESSION array values:
Array ( [IDNO] => A1234 [DPT_COD] => Array ( [0] => 1402 [1] => B402 ) )

New SESSION array values:
Array ( [IDNO] => Z5678 [DPT_COD] => foobar )


In machine 2

The browser show:
Original SESSION array values:
Array ( [IDNO] => A1234 [DPT_COD] => Array ( [0] => 1402 [1] => B402 ) )

New SESSION array values:
Array ( [IDNO] => A1234 [DPT_COD] => Array ( [0] => 1402 [1] => B402 ) )

I think the result in machine 2 is what it should be.
But I don’t know why macheine 1 show that diffrent result.

The answer is someone turn on register_globals in php.ini in machine 1.


Oracle中設定auto increment的一些相關筆記

清空資料表

truncate table TABLE_NAME;


設定Auto Increment
參考資料:
http://www.lifeaftercoffee.com/2006/02/17/how-to-create-auto-increment-columns-in-oracle/

先建立一個sequence

create sequence SEQUENCE_NAME
start with 1
increment by 1
nocache;

再建立一個trigger

create or replace trigger TRIGGER_NAME
before insert
on TABLE_NAME
referencing NEW as NEW
for each row
begin
select SEQUENCE_NAME.nextval into :NEW.AUTO_INCREMENT_COLUMN from dual;
end;
/

這樣就完成了

SEQUENCE有下列參數:MINVALUE、MAXVALUE、START WITH、INCREMENT BY、CACHE、NOCACHE、CYCLE

要加nocache,sequence才不會亂跳

SEQUENCE到達最大值之前不能重新計數,只能用DROP刪除後再重新CREATE建立。
可以用ALTER來修改SEQUENCE的參數

ALTER SEQUENCE seq01
INCREMENT BY 100;

用NEXTVAL取得下一個值

SELECT seq01.NEXTVAL FROM DUAL;


用CURRVAL取的目前值

SELECT seq01.CURRVAL FROM DUAL;


Gentoo的套件透過emerge更新時的注意事項

根據CD長輩的教誨
首先

emerge -DuN world

接著

emerge –depclean

最後

revdep-rebuild

這期間如有套件出錯,則

emerge –oneshot 套件

這樣可重編一次該套件,卻不把該套件加入world list裡。


IPv6, openssh, and tcp_wrappers

在一台新重灌好的Gentoo server裡編了IPv6的支援,在開啟openssh時,會有

refused connect from 0.0.0.0

這樣的error message出現,tcp_wrappers的hosts.deny運作也不太正常。
後來找到解決方法為,讓openssh只使用IPv4,在/etc/ssh/sshd_config裡做了以下設定即可

AddressFamily inet


Follow

Get every new post delivered to your Inbox.