顯示具有 程式設計 標籤的文章。 顯示所有文章
顯示具有 程式設計 標籤的文章。 顯示所有文章

星期二, 4月 15, 2014

mysql 常用指令

重新啟用
# service mysql restart
# /etc/rc.d/init.d/mysqld restart

將欄位 a 的 varchar 型態轉成 int 進行排序
select * from test ORDER BY CAST(`a` AS DECIMAL(10,2)) DESC

匯出
> mysqldump -u root -p --quick --default-character-set=utf8 --complete-insert --add-drop-table --no-create-info --no-data --compress --result-file=/home/sean/comtrend1.sql comtrend table

匯入
1)先新增DB
> /usr/local/mysql/bin/mysqladmin -u root -p create comtrend
2)將結構跟資料匯入
> /usr/local/mysql/bin/mysql -u root -p comtrend < /home/sean/comtrend1.sql

TRUNCATE TABLE `authors`

GRANT SELECT,DELETE,INSERT,UPDATE ON itry.* TO itry@localhost IDENTIFIED BY 'itryedcrfv';

FLUSH PRIVILEGES;

SET PASSWORD FOR 'root'@ 'localhost' = PASSWORD( '*****' )

4.1 版之前的舊編碼方式
SET PASSWORD FOR 'root'@ 'localhost' = OLD_PASSWORD( '*****' )

SELECT * FROM `members` WHERE `user` LIKE CONVERT( _utf8 'sean' USING big5 ) COLLATE big5_chinese_ci LIMIT 0 , 30

SELECT * FROM table_references WHERE where_definition ORDER BY RAND()

修復資料表
REPAIR TABLE phpbb_search_wordlist

ALTER TABLE table_name ADD COLUMN column_name type AFTER column_name1

ALTER TABLE table_name CHANGE COLUMN column_name column_name1 type

重設自動新增的數值
ALTER TABLE `pweb_categories` PACK_KEYS =0 CHECKSUM =0 DELAY_KEY_WRITE =0 AUTO_INCREMENT =1

可加快 mysql 的設定 /etc/my.cnf
max_connect_errors = 1844674407370954751
connect_timeout = 20
skip-name-resolve
(* 另一個解法:在 /etc/hosts中加入新加的 Web 內網 ip 主機名稱)
#skip-networking
#skip-external-locking
slave_net_timeout = 30

星期一, 4月 14, 2014

常用 html 語法

flash 語法

wmode 一共有 window、opaque、transparent 3 種

window:預設,無法設定 z-index,會遮住所有重疊到的 HTML 元素,效能最好。
opaque:不透明,可設定 z-index。
transparent:背景透明,可設定 z-index,效能最好。

星期四, 5月 24, 2012

php_mcrypt.dll 無法載入 (windows)

先在 Apache 的設定檔 httpd.conf 裡加上:

PHPIniDir "C:\AppServ\php5"
#指定 php.ini 路徑

php.ini 加上:

extension_dir = "C:\AppServ\php5\ext"
#指定 dll 檔案路徑

extension=php_mcrypt.dll
#載入模組

重啟 Apache,如果還是不行,就是找不到相依的 libmcrypt.dll 檔案。
所以要把 C:\AppServ\php\libmcrypt.dll 複製到 C:\Windows 路徑下。

重新啟動 Apache,收工。

星期三, 11月 02, 2011

TortoiseGit 安裝 ssh 連接設定


需安裝的軟體:
msysgit http://code.google.com/p/msysgit/
TortoiseGit http://code.google.com/p/tortoisegit/
Putty http://www.chiark.greenend.org.uk/~sgtatham/putty/

  1. 下載 msysGit-fullinstall-1.7.7.1-preview20111027.exe,執行安裝。
  2. 下載 TortoiseGit-1.7.4.0-32bit.msi ,執行安裝。設定 MSysGit Path = C:\msysgit\msysgit\bin,Extern DLL Path = C:\msysgit\msysgit\mingw\bin。
  3. 下載 putty.exe, plink.exe, pageant.exe, puttygen.exe。利用 puttygen 產生 key pair, 將上方區塊內的內容存成 id_rsa.pub (public key),點選 Save private key 存成 id_rsa.ppk。
  4. 將 public key 上傳到 Git server,存到 ssh 資料夾 #cat id_rsa.pub >> .ssh/authorized_keys。
  5. 使用 TortoiseGit Clone 時,選擇剛存的 private key,URL 會是像sean@192.168.10.1:repository。
  6.  設定開機啟動 pageant,建立 windows 捷徑 "C:\Program Files\TortoiseGit\bin\pageant.exe" "C:\Users\user\id_rsa.ppk"。

星期一, 6月 21, 2010

PHP 壓縮設定


php.ini 的設定

ob_gzhandler 壓縮方式:
output_buffering = 4096 ;壓縮多少Bytes後就立即傳送給Client端
output_handler = ob_gzhandler

zlib 壓縮方式的設定:
zlib.output_compression = On
zlib.output_compression_level = 6 ;壓縮比率(0:不壓縮,9:最大壓縮)
;zlib.output_handler = ;請註解一行,或將值設定為空白
** ob_gzhandler 跟 zlib 只能選一種

星期四, 5月 17, 2007

簡單用 PHP 建立 RSS 的方法


最近找了一個好用的 RSS 產生工具
可以很簡單並且快速的讓網站具有 RSS 功能
要修改的程式碼不超過 30 行
以下是步驟

1. 下載 phpFeedCreator 工具
2. 新建一個 rss.php

// Include phpFeedCreator
require_once('phpFeedCreator/phpFeedCreator.php');

// sets rss parameters
$pfc->setRssParams("2.0");

// sets channel elements (title, link, description)
$pfc->setChannelElements("RSS Channel Title", "http://your_website", "Channel Description");

// adds a item (title, link, description)
$pfc->addItem("title1", "http://title1_url", "desc1");

// adds another item (title, link, description)
$pfc->addItem("title2", "http://title_url2", "desc2");

// puts out full rss document
$pfc->createFeed();

?>

3. 用 http://your_website/rss.php 訂閱 RSS

星期三, 12月 13, 2006

jQuery AJAX select 選單

js 下載網址:http://www.texotela.co.uk/code/jquery/select/

$('#product_type').change(function() {

    // 觸發商品名稱下拉式選單
    $('#product_id').removeOption(/.?/).ajaxAddOption(
        '/sc/promo/json_product.php',
        {'pid': $(this).val()},
        false,
    );
    $('#row3').hide();
});

星期三, 5月 24, 2006

所見即所得的線上編輯器 -- FCKedit


簡易用法
  1. 在<head></head>引入FCKedit。
    <script type="text/javascript" src="includes/FCKeditor/fckeditor.js"></script>

  2. 替換<textarea>。
    <textarea name="description">sample</textarea>
    <script type="text/javascript">
    <!--
    var oFCKeditor = new FCKeditor("description");
    oFCKeditor.BasePath = "includes/FCKeditor/";
    oFCKeditor.Height = "500";
    oFCKeditor.ReplaceTextarea();
    //-->
    </script>

官方網站 http://www.fckeditor.net/

星期五, 12月 16, 2005

PHPMailer


不想用內建的mail()發信嗎?
這裡推薦一個不錯的發信程式, 有smtp, sendmail, mail 3種可選擇.
簡單的使用方法如下:

//引入phpmailer
require_once("class.phpmailer.php");


//初始化
$phpmail = new PHPMailer();

$phpmail->From = "user@domain.com";
$phpmail->FromName = "webmaster";
$phpmail->Host = ""smtp.domain.com;

//寄送方法(smtp, sendmail, mail)
$phpmail->Mailer = "smtp";
$phpmail->SMTPAuth = true;
$phpmail->Username = "smtp_user";
$phpmail->Password = "smtp_pwd";

//收件人
$phpmail->AddAddress("friend@hisdomain.com");
$phpmail->Subject = "測試";
$phpmail->Body = $body;
$phpmail->CharSet = "big5";
$phpmail->IsHTML(true);

//加入附檔
$phpmail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip");

if ( !$phpmail->Send() ) {
echo $phpmail->ErrorInfo;

}


官方網站 http://phpmailer.sourceforge.net/

利用 gmail 當 smtp 寄送郵件設定方式

 $phpmail->From = $mail_from;
    $phpmail->FromName = $mail_from_name;
    $phpmail->Host = $smtp_server;
    $phpmail->Mailer = $mailer;
    if (strpos($to_email, ",") === false) {
        $phpmail->AddAddress($to_email);
    } else {
        $email = explode(",", $to_email);
        for($i=0; $i<count($email); $i++) {
            $phpmail->AddBcc($email[$i]);
        }
    }
    $phpmail->Subject = $subject;
    $phpmail->Body = $sendata;
    $phpmail->CharSet = $mail_charset;
    $phpmail->IsHTML($is_html);
    $phpmail->Encoding = "base64";
    $phpmail->addEmbeddedImage($cardimagepath."/".$image_name, 'my-photo');
    if ($smtp_auth === true) {
        $phpmail->SMTPAuth = true;
        $phpmail->SMTPSecure = $smtp_secure; //gmail SMTP using SSL
        $phpmail->Port = $smtp_port; //gmail using 465 port
        $phpmail->Username = $smtp_username;
        $phpmail->Password = $smtp_password;
    }

    if (!$phpmail->Send()) {
        echo $phpmail->ErrorInfo;
        die();
    }