歡迎光臨, 訪客. 請先 登入註冊一個帳號.
三月 19, 2024, 02:40:50 下午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  開發  |  核心補強  |  聯結不到資料庫時如何轉向其他備份頁面 « 上篇主題 下篇主題 »
頁: [1] 2
作者 主題: 聯結不到資料庫時如何轉向其他備份頁面  (閱讀 65571 次)
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 於: 六月 01, 2005, 04:43:29 下午 »

這應該不是外掛的功能(當然,我有可能猜錯了 :P)

由於我用的虛擬主機,偶爾會連不上 MySQL,我就自己寫了個簡單程式輸出靜態頁面 HTML 作為備份。

請問我應該從那裡下手去改錯誤處理呢?

從錯誤訊息來看,可能是連結 MySQL 太多 threads 或是 memory 不足的錯誤,這是 pLog 的處理範圍嗎?

環境:
-----------------------------------------
Linux(不知道是哪個版本)
Apache Release    10333100
Apache API Version    19990320
PHP Version 4.3.11
MySQL Client API version    4.0.24
-----------------------------------------

我的超簡單輸出程式如下,提供給需要的人。
(由於這支程式輸出全部文章到同一個檔案,文章很多的人可能要考慮清楚這樣做是否合適,或者依情況自行修改)
----------------

<?php
// 參數設定

// 資料庫所在
$strMySQL = "xxx";
// 資料庫名稱
$strDatabase = "xxx";
// 資料庫使用者名稱
$strUserName = "xxx";
// 資料庫密碼
$strPassword = "xxx";
// plog 的資料表字首
$strPlogPrefix = "xxx";
// 輸出路徑,最後面要加斜線(目錄要設定為可讀寫,例如777)
$strArticleIndexPath = "xxx";
// 輸出備份檔名
$strOutput = "xxx";


// 聯結資料庫
$link = mysql_connect($strMySQL, $strUserName, $strPassword) or
die("mysql_connect() failed.");

mysql_select_db($strDatabase, $link) or
die("mysql_select_db() failed.");

// 放文章的變數
$strFileContent = <<<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh_TW"  lang="zh_TW" dir="ltr">
 <head>
  <title>White Cloud's Blog</title>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>

<body><center>
<font size=6 color=green>White Cloud's Blog</font>
<br>目前暫時連結不上資料庫,這是備份頁面<br><br>
EOT;

$strTable = $strPlogPrefix."articles_text";

   $sql = "select article_id,topic,text from $strTable order by article_id desc";

   $r = mysql_query($sql);

   while ($row = mysql_fetch_object($r)) {

    $strArticleID = $row->article_id;

    $strTopic = $row->topic;

    $strText = $row->text;
   
$strFileContent = $strFileContent.'<table width="80%" border="1"><tr><td>';
// $strFileContent = $strFileContent.$strArticleID;
// $strFileContent = $strFileContent."<br>";
 $strFileContent = $strFileContent.'<font size=5><b>';
 $strFileContent = $strFileContent.$strTopic;
 $strFileContent = $strFileContent.'</b></font>';
 $strFileContent = $strFileContent."<br><br>";
 $strFileContent = $strFileContent.$strText;
 $strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent."<td><tr><table><br><br>";

    }

$strFileContent = $strFileContent."All content copyright 咖啡杯 2004 White Cloud's Blog";

$strFileContent = $strFileContent."</center></body></html>";
 
 
// 輸出成為 HTML   
//echo  $strFileContent;   
$fp = fopen($strArticleIndexPath.$strOutput, "w");
      fputs($fp, $strFileContent);
fclose($fp);

echo "OK";   
?>
« 最後編輯時間: 三月 30, 2006, 12:06:35 上午 由 WhiteCloud » 已記錄
markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #1 於: 六月 02, 2005, 10:35:56 上午 »

這方法不錯喔!呵呵!也可以用這樣來備份文章。

Mark
已記錄

WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #2 於: 六月 02, 2005, 12:04:09 下午 »

如果要完整的備份方案, Mark 的匯出匯入 RSS
http://forum.lifetype.org.tw/index.php?topic=713.0
才是更好的方法。:-)

這是不得已的方法,因為 PHP 似乎都 OK,但是 MySQL 在某個時段會有問題(不知道是不是固定的維護時間)。

哈,這支簡單程式竟然忘了用變數指定 Database,趕快改正。 :P

請問這種錯誤處理該從哪下手較好,我對 pLog 的整個架構還不清楚.... 有沒有對於架構的相關描述文件呢?
已記錄
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #3 於: 六月 02, 2005, 12:55:44 下午 »

在 pLog 總站的文件中發現了一篇 MVC 的文件,就開始K 吧....

http://wiki.lifetype.net/index.php/Model-View-Controller_in_pLog
已記錄
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #4 於: 六月 02, 2005, 03:47:46 下午 »

引用自: WhiteCloud
在 pLog 總站的文件中發現了一篇 MVC 的文件,就開始K 吧....

http://wiki.lifetype.net/index.php/Model-View-Controller_in_pLog

哇!這個很精采哦!

加油!
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #5 於: 六月 02, 2005, 10:59:41 下午 »

引用自: lss
引用自: WhiteCloud
在 pLog 總站的文件中發現了一篇 MVC 的文件,就開始K 吧....

http://wiki.lifetype.net/index.php/Model-View-Controller_in_pLog

哇!這個很精采哦!

加油!


對 MVC 有興趣可以看一下 ROR (Ruby on Rails) 跟 Prado (PHP5) 這兩個 Framework, 資料目前也比較多喔。正在K書中.... 微笑

Mark
已記錄

markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #6 於: 六月 02, 2005, 11:00:31 下午 »

引用自: markwu
引用自: lss
引用自: WhiteCloud
在 pLog 總站的文件中發現了一篇 MVC 的文件,就開始K 吧....

http://wiki.lifetype.net/index.php/Model-View-Controller_in_pLog

哇!這個很精采哦!

加油!


對 MVC 有興趣可以看一下 ROR (Ruby on Rails) 跟 Prado (PHP5) 這兩個 Framework, 資料目前也比較多喔。正在K書中.... 微笑

Mark


忘了說,如果熟 Java ,可以看 Struts ... 他的資源大概是目前最多的。

Mark
已記錄

WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #7 於: 六月 03, 2005, 11:11:21 上午 »

引用
markwu 寫到:
引用
lss 寫到:
引用
WhiteCloud 寫到:
在 pLog 總站的文件中發現了一篇 MVC 的文件,就開始K 吧....

http://wiki.lifetype.net/index.php/Model-View-Controller_in_pLog

哇!這個很精采哦!

加油!



對 MVC 有興趣可以看一下 ROR (Ruby on Rails) 跟 Prado (PHP5) 這兩個 Framework, 資料目前也比較多喔。正在K書中.... 微笑

Mark


引用
忘了說,如果熟 Java ,可以看 Struts ... 他的資源大概是目前最多的。

Mark


非常感謝 Mark 提供這些資訊和 lss 的鼓勵 微笑

Java 我經驗不多,Ruby 更是沒用過,看來我要努力的還多著呢 吐舌頭

Mark 所說的正好都有網站,列出給所有有興趣的朋友參考:

http://www.rubyonrails.org/
http://www.xisc.com/
http://struts.apache.org/
已記錄
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #8 於: 六月 03, 2005, 12:17:23 下午 »

連不上 MySQL 找到原因了,還是 Google 大神幫的忙 吐舌頭

這是 Linux 的 glibc 需要升級!!

資料來源:
http://penguin.im.cyut.edu.tw/mysql/manual_Installing.html#Linux-RedHat51
已記錄
Anonymous
訪客
« 回覆文章 #9 於: 六月 08, 2005, 08:03:18 下午 »

之前寫了一個小程式備份全部 pLog 中的文章,這回做了小小的改版,與之前的版本有些差別:

   1. 輸出文章備份時,也同時輸出作者名稱和撰寫日期。
   2. 自動使用安裝 pLog 時的目錄,所以這個新程式要擺在 pLog 安裝目錄之下,好處是不用設定資料庫所在,使用者名稱....等等
   3. 預設輸出檔名為 article.htm 請自行修改
   4. 網誌名稱請自行修改
   5. 備份完成會自動轉到輸出的靜態 HTML 檔案去。


程式如下:

--------------------------------------------------------------------

<?php
// 參數設定
if (!defined( "PLOG_CLASS_PATH" )) {
define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
}
include_once( PLOG_CLASS_PATH."config/config.properties.php" );

// 資料庫所在
$strMySQL = $config["db_host"];
// 資料庫名稱
$strDatabase = $config["db_database"];
// 資料庫使用者名稱
$strUserName = $config["db_username"];
// 資料庫密碼
$strPassword = $config["db_password"];
// plog 的資料表字首
$strPlogPrefix = $config["db_prefix"];
// 輸出路徑,最後面要加斜線(目錄要設定為可讀寫,例如777)
$strArticleIndexPath = PLOG_CLASS_PATH;
// 輸出備份檔名
$strOutput = "article.htm";
// 網誌名稱
$strBlogName = "White Cloud's Blog";


// 聯結資料庫
$link = mysql_connect($strMySQL, $strUserName, $strPassword) or
die("mysql_connect() failed.");

mysql_select_db($strDatabase, $link) or
die("mysql_select_db() failed.");

// 放文章的變數
$strFileContent = <<<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh_TW" lang="zh_TW" dir="ltr">
<head>
<title>$strBlogName</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>

<body><center>
<font size=6 color=green>White Cloud's Blog</font>
<br>目前暫時連結不上資料庫,這是備份頁面<br><br>
EOT;

$strTableArticleText = $strPlogPrefix."articles_text";
$strTableArticle = $strPlogPrefix."articles";
$strTableUsers = $strPlogPrefix."users";

$sql = "select article_id,topic,text,user,date from $strTableArticleText,$strTableArticle,$strTableUsers where $strTableArticleText.article_id = $strTableArticle.id and $strTableUsers.id = $strTableArticle.user_id order by article_id desc";

$r = mysql_query($sql);

while ($row = mysql_fetch_object($r)) {

$strArticleID = $row->article_id;

$strTopic = $row->topic;

$strText = $row->text;

$strAuthor = $row->user;

$strDate = $row->date;

$strDate = substr($strDate,0,4)."/".substr($strDate,4,2)."/".substr($strDate,6,2)." ".substr($strDate,8,2).":".substr($strDate,10,2).":".substr($strDate,12,2);

$strFileContent = $strFileContent.'<table width="80%" border="1"><tr><td>';
// $strFileContent = $strFileContent.$strArticleID;
// $strFileContent = $strFileContent."<br>";
$strFileContent = $strFileContent.'<font size=5><b>';
$strFileContent = $strFileContent.$strTopic;
$strFileContent = $strFileContent.'</b></font>';
$strFileContent = $strFileContent."<br>";
$strFileContent = $strFileContent.$strAuthor;
$strFileContent = $strFileContent." ";
$strFileContent = $strFileContent.$strDate;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent.$strText;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent."<td><tr><table><br><br>";

}

$strFileContent = $strFileContent = $strFileContent."All content copyright 咖啡杯 2004 $strBlogName";

$strFileContent = $strFileContent = $strFileContent."</center></body></html>";


// 輸出成為 HTML
//echo $strFileContent;
$fp = fopen($strArticleIndexPath.$strOutput, "w");
fputs($fp, $strFileContent);
fclose($fp);

header("Location: $strOutput");
?>
已記錄
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #10 於: 六月 09, 2005, 01:31:07 上午 »

可以用這個做出『本站文章全部打包』的功能,讓網友可以存檔回去慢慢看。

此時,程式最後一行
header("Location: $strOutput");
如果改為
echo "OK";
這樣輸出後就不會轉向靜態頁面(這支程式由站長執行即可,其他網友只需要靜態頁面)。

然後在適當的模板中加入靜態 HTML 的超連結即可。
已記錄
markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #11 於: 六月 10, 2005, 10:36:14 上午 »

引用自: WhiteCloud
可以用這個做出『本站文章全部打包』的功能,讓網友可以存檔回去慢慢看。

此時,程式最後一行
header("Location: $strOutput");
如果改為
echo "OK";
這樣輸出後就不會轉向靜態頁面(這支程式由站長執行即可,其他網友只需要靜態頁面)。

然後在適當的模板中加入靜態 HTML 的超連結即可。


WhiteCloud,你可以試用 pLog 的 API 來做 export 喔,我保證會更麻煩,但是你會學到不少喔。

你可以參考一下:
http://forums.lifetype.net/viewtopic.php?t=2421&highlight=articles
http://forums.lifetype.net/viewtopic.php?t=2264&highlight=articles

加油!

Mark
已記錄

WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #12 於: 六月 10, 2005, 11:29:21 上午 »

引用
WhiteCloud,你可以試用 pLog 的 API 來做 export 喔,我保證會更麻煩,但是你會學到不少喔。

你可以參考一下:
http://forums.lifetype.net/viewtopic.php?t=2421&highlight=articles
http://forums.lifetype.net/viewtopic.php?t=2264&highlight=articles

加油!

Mark


多謝 Mark 微笑
API 我還不熟,所以才會用最簡單的方法完成我要的東西。有範例可循太棒了,我就找個時間來練習 API 的使用,做出同樣功能 微笑
已記錄
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #13 於: 六月 25, 2005, 11:38:33 上午 »

感謝 Mark 提供的資料,我使用 pLog 內建的物件來重寫備份程式。

程式變動:

改成呼叫 pLog 的 Article 類別物件

可設定網誌編號來備份不同 blog

取消顯示作者名

------------------------------------------------------------------------

<?php
    if (!defined( "PLOG_CLASS_PATH" )) {
        define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
    }

    include_once( PLOG_CLASS_PATH."config/config.properties.php" );
    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );

// plog 的資料表字首
$strPlogPrefix = $config["db_prefix"];
// 輸出路徑,最後面要加斜線(目錄要設定為可讀寫,例如777)
$strArticleIndexPath = PLOG_CLASS_PATH;
// 輸出備份檔名
$strOutput = "article.htm";
// 網誌名稱
$strBlogName = "White Cloud's Blog";
// 網誌編號
$strBlogNumber = "1";



// 放文章的變數
$strFileContent = <<<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh_TW" lang="zh_TW" dir="ltr">
<head>
<title>$strBlogName</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>

<body><center>
<font size=6 color=green>$strBlogName </font>
<br>這是備份頁面,歡迎存檔慢慢欣賞 :-)<br><br>
EOT;

//    $query = "SELECT * FROM plog_articles As a, plog_articles_text As at WHERE a.id=at.article_id AND a.blog_id = 1 ORDER BY a.date DESC";
   

$strTableArticleText = $strPlogPrefix."articles_text";
$strTableArticle = $strPlogPrefix."articles";
$strTableUsers = $strPlogPrefix."users";

$sql = "select * from $strTableArticleText,$strTableArticle where $strTableArticleText.article_id = $strTableArticle.id and $strTableArticle.blog_id = $strBlogNumber order by article_id desc";

    $articles = new Articles();
    $result = $articles->getBlogArticlesByQuery( $sql );  

foreach( $result as $article ) {

$strTopic = $article->getTopic();

$strText = $article->getText();

//$strAuthor = $article->getUser();

$strDate = $article->getDate();

// 由於改用 MySQL 4.1 的關係,取消此行
//$strDate = substr($strDate,0,4)."/".substr($strDate,4,2)."/".substr($strDate,6,2)." ".substr($strDate,8,2).":".substr($strDate,10,2).":".substr($strDate,12,2);

$strFileContent = $strFileContent.'<table width="80%" border="1"><tr><td>';
// $strFileContent = $strFileContent.$strArticleID;
// $strFileContent = $strFileContent."<br>";
$strFileContent = $strFileContent.'<font size=5><b>';
$strFileContent = $strFileContent.$strTopic;
$strFileContent = $strFileContent.'</b></font>';
$strFileContent = $strFileContent."<br>";
//$strFileContent = $strFileContent.$strAuthor;
//$strFileContent = $strFileContent." ";
$strFileContent = $strFileContent.$strDate;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent.$strText;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent."<td><tr><table><br><br>";

}

$strFileContent = $strFileContent = $strFileContent."All content copyright (c) 2004 $strBlogName";

$strFileContent = $strFileContent = $strFileContent."</center></body></html>";


// 輸出成為 HTML
//echo $strFileContent;
$fp = fopen($strArticleIndexPath.$strOutput, "w");
fputs($fp, $strFileContent);
fclose($fp);

header("Location: $strOutput");
//echo "OK";
?>
已記錄
markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #14 於: 六月 27, 2005, 12:01:40 上午 »

這一個真的改的很棒。

Mark
已記錄

頁: [1] 2
LifeType 中文開發論壇  |  開發  |  核心補強  |  聯結不到資料庫時如何轉向其他備份頁面 « 上篇主題 下篇主題 »
    前往: