请看我的PHP代码:
PHP:
$username = 'kia';
$pswd = 'kiakia';
$db = 'jahaad';
$kaan = new PDO('mysql:host=localhost; dbname = jahaad', $username, $pswd);
if ($kaan) { echo 'Connected<br />'; }
else { echo 'Not Connected'; }
$address = "../letters/Assistance01/office01/letter001.txt";
$open = fopen($address, 'r');
$size = filesize($address);
$file = fread($open, ($size*4));
fclose($open);
$filename = basename($address);
echo '<hr />' . $filename;
$type = strstr($filename, '.');
echo '<br /> ' . $type;
$recieveTime = date('Y/m/d H:m:s');
echo '<br />' . $recieveTime;
$from = 'test';
$sql = 'INSERT (`filename`, `filetype`, `recieve`, `from`, `file`) INTO `jahaad`.`assis01_office01` VALUES(:filename, :filetype, :recieve, :from, :file)';
$result = $kaan->prepare($sql);
$result->execute(array(':filename'=>$filename, ':filetype'=>$type, ':recieve'=>$recieveTime, ':from'=>$from, ':file'=>$file));
if ($result) {
echo '<br />OK';
}
else {
echo '<br />Problem';
}
除了文件列,我的数据库中的每个列类型都是 VARCHAR。当我运行代码时,$result
是真的!!!但我的数据库中没有添加任何内容...你能告诉我有什么问题吗???
编辑:
这是因为我在编写查询时粗心......
希望你不要这样做......