2010-10-14

mu 移站的備忘

因為mu的系統,把主站網址都存成資料庫了,所以要用REPLACE 去更新mysql中的訊息



$dbs = array("bsblogs"=>array("http://the.src.site.dns/pathto/","http://the.new.site.dns/","the.src.site.dns","the.new.site.dns","/pathto/","/"));
foreach ( $dbs as $dbname => $fixv ){
$fix_wp_db->setQuery("USE the_database_name;");
$fix_wp_db->query();
$fix_wp_db->setQuery("SHOW TABLES;");
$tables = $fix_wp_db->loadObjectList();
//print_r($fix_wp_db);
foreach($tables as $tb){
if( preg_match('/[0-9+]_options$/',$tb->Tables_in_the_database_name) ){
echo $tb->Tables_in_the_database_name."
";
$fix_wp_db->setQuery("UPDATE $tb->Tables_in_the_database_name SET option_value = REPLACE( `option_value` , '$fixv[0]', '$fixv[1]' ) ;");
$tables = $fix_wp_db->query();
if(!$fix_wp_db->_errorMsg)echo $fix_wp_db->getQuery()."
";
else echo $fix_wp_db->_errorMsg."
";
}

if( preg_match('/[0-9+]_posts$/',$tb->Tables_in_the_database_name) ){
echo $tb->Tables_in_the_database_name."
";
$fix_wp_db->setQuery("UPDATE $tb->Tables_in_the_database_name SET post_content = REPLACE( `post_content` , '$fixv[0]', '$fixv[1]' ) ;");
$tables = $fix_wp_db->query();
if(!$fix_wp_db->_errorMsg)echo $fix_wp_db->getQuery()."
";
else echo $fix_wp_db->_errorMsg."
";
}


}
$fix_wp_db->setQuery("UPDATE wp_site SET domain = REPLACE( `domain` , '$fixv[2]', '$fixv[3]' ) , path = REPLACE( `path` , '$fixv[4]', '$fixv[5]' );");
$tables = $fix_wp_db->query();
if(!$fix_wp_db->_errorMsg)echo $fix_wp_db->getQuery()."
";
else echo $fix_wp_db->_errorMsg."
";
$fix_wp_db->setQuery("UPDATE wp_blogs SET domain = REPLACE( `domain` , '$fixv[2]', '$fixv[3]' ) , path = REPLACE( `path` , '$fixv[4]', '$fixv[5]' );");
$tables = $fix_wp_db->query();
if(!$fix_wp_db->_errorMsg)echo $fix_wp_db->getQuery()."
";
else echo $fix_wp_db->_errorMsg."
";
}


.htaccess 也要改

2010-10-13

解決:不小心把ubuntu 的預設帳號的群組取消了sudo功能造成 is not in the sudoers file. This incident will be reported

如果你在"本機"上的桌面有登入,且只是封鎖,並末登出的話,可以直接登入
開 終端機

usermod -G adm,admin username
去加入 sudo 的權限群組

沒有的話就要回本機前面,直接重開機
"進入 recover mode ,選擇root"
進入系統
然後把帳號加入到admin

參考來源:不能用sudo 也不能切換root了 [論壇 - 新手村] | Ubuntu 正體中文站

linux 如何搜尋文件內容

#> find . -type f -exec grep 'mingtian' -l {} \;
grep -l :是顯示匹配的內容的文件名字!
>#> find . -type f name "*.php" -exec grep 'mingtian' -l {} \;
只查 *.php 的文件


參考來源:linux下查找文件內容!find grep(小壽原創) - 解決的問題 - linux研究(小壽的天下!): "linux下查找文件內容!find grep(小壽原創)

2010-10-12

putty ssh 連線閒置不斷線設定

在 Connection
Seconds between keppalives 打 5 (每5秒送1個封包)
並在底下有一個 Enable TCP keepalives ..... ,打勾它就好



參考:putty ssh 連線閒置不斷線設定 - NIL - coding or die?

2010-10-09

手機瀏覽器的agents名單大全

手機瀏覽器的agents名單大全
http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones

2010-09-27

ubuntu 10.04 要使用freetds 才能連入 mssql

因為我用 php 5.2.x 版的
所以先重裝一次 http://z-win.blogspot.com/2010/05/ubuntu-php-52x.html
最後加上
sudo apt-get install freetds-bin
sudo aptitude install -t karmic php5-sybase
#改freetds 設定(這是我自已要用的)
sudo vim /etc/freetds/freetds.conf
#在[global]加上
text size = 104857600 #大小能到100b
client charset = UTF-8 #預設utf-8
#改mssql_connect的語言
sudo vim /etc/php5/apache2/php.ini
#加入
mssql.charset = "UTF-8"
sudo /etc/init.d/apache2 restart
#test方法
tsql -H mssql.ip -p 1433 -U username
#輸入password後出現 1> 就成功了
#php



#也可以用 匿名主機 方式連入,但mssql 要sp4以上
sudo vim /etc/freetds/freetds.conf
#加入
[mssql_con1]
host = this.con1.server
port = 1433
tds version = 8.0

#test方法
tsql -S mssql_con1 -U username
#輸入password後出現 1> 就成功了

#php測試
<?php
echo mssql_connect('mssql_con1', 'username', 'password') 
? 'success' 
: 'failure';
?> 
當mssql的資料是 uniqueidentifier 在LINUX上的FREETDS 要用  mssql_guid_string 或 在SQL 用 cast(欄位名 as varchar(36)) 轉換字元, 在windows用com 時會自動轉
uniqueidentifier  的說明:
http://technet.microsoft.com/zh-tw/library/ms190215.aspx
php的其它解法可以看:
http://uk.php.net/manual/en/function.mssql-guid-string.php


如果發生:
Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.
請使用底下語法:

SET ANSI_WARNINGS ON
SET ANSI_NULLS ON

參考:
http://social.msdn.microsoft.com/Forums/en/sqldataaccess/thread/1d501b57-fc58-4fbe-9bec-6c38ad158a62

2010-09-23