函式名稱:cubrid_lob_export()
適用版本:CUBRID 9.1.0 或更高版本
說明:cubrid_lob_export() 函式用於將 CLOB/BLOB 資料匯出到檔案或字串中。它可以將 CLOB/BLOB 資料儲存為檔案,或將其輸出為字串。
語法:cubrid_lob_export(resource $lob_identifier, string $file_path)
引數:
- $lob_identifier:CUBRID LOB 資料的識別符號,透過使用 cubrid_lob_get() 或 cubrid_lob2_new() 獲得。
- $file_path:指定儲存 CLOB/BLOB 資料的檔案路徑。
返回值:
- 成功時,返回儲存的位元組數(整數)。
- 失敗時,返回 false。
示例:
- 匯出 CLOB 資料到檔案:
<?php
$conn = cubrid_connect("localhost", 33000, "testdb", "username", "password");
$res = cubrid_execute($conn, "SELECT lob_column FROM sample_table WHERE id=1");
$row = cubrid_fetch_assoc($res);
$clob_data = cubrid_lob_get($row['lob_column']);
$clob_file = "/path/to/save/clob.txt";
if (cubrid_lob_export($clob_data, $clob_file) !== false) {
echo "CLOB 資料匯出成功!";
} else {
echo "CLOB 資料匯出失敗!";
}
cubrid_close($conn);
?>
- 匯出 BLOB 資料到字串:
<?php
$conn = cubrid_connect("localhost", 33000, "testdb", "username", "password");
$res = cubrid_execute($conn, "SELECT lob_column FROM sample_table WHERE id=1");
$row = cubrid_fetch_assoc($res);
$blob_data = cubrid_lob_get($row['lob_column']);
$string_data = "";
if (cubrid_lob_export($blob_data, $string_data) !== false) {
echo "BLOB 資料匯出成功!";
echo $string_data;
} else {
echo "BLOB 資料匯出失敗!";
}
cubrid_close($conn);
?>
以上示例演示瞭如何使用 cubrid_lob_export() 函式將 CLOB 資料儲存到檔案和將 BLOB 資料匯出為字串。請確保替換示例程式碼中的主機名、資料庫名、使用者名稱和密碼以正確連線到您的資料庫。