<?php

/* Test script to upload a file and store in a BLOB field */
/* Change the pass according to your environment */

$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. Please uncomment to reproduce the problem */
mysql_query ("SET NAMES cp932");

/* Insert the data into the table created by the statement:

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);
?>
