• atwiki
  • MyOSS
  • ファイルをBLOBフィールドに挿入する方法

MyOSS

ファイルをBLOBフィールドに挿入する方法

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集
<?php

/* Test script to upload a file and store in a BLOB  field */

$localfile =  file_get_contents("/home/shuichi/9500.txt");

/* Connect to MySQL */
$link = mysql_connect("localhost:5015","root","")
or die("Could not connect"); 

/* Select Database */
mysql_select_db("test")
or die("Could not select DB");

/* Print the value before escape */
echo ("Before escape:\t");
echo bin2hex($localfile);
print ("<br>\n");

/* Escape the file */
$escapedfile = mysql_real_escape_string($localfile);

/* Print the values after escape */
echo ("After escape:\t");
echo bin2hex($escapedfile);

/* Set character set to cp932 */
//mysql_query ("SET NAMES cp932");

/* Insert into BLOB table

CREATE TABLE `blob_tbl` (
 `c1` BLOB
) ENGINE = MyISAM DEFAULT CHARSET = cp932;

*/


$result = mysql_query ("INSERT INTO blob_tbl (c1)  select '$escapedfile'")
or die ("invalid query" . mysql_error(). "\n");

/* Close the connection */
mysql_close($link);
?>

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

目安箱バナー