我想将文件系统上存储的包含 CalDAV 指令的文件存储到数据库中,以便与 SabreDAV 一起使用。以下代码片段创建的文件运行良好:
$datei = fopen("./calendar/temp/tmp_event".$eventrand,"w");
$caldavcontent = "BEGIN:VCALENDAR[...]";
fwrite($datei, $caldavcontent,2000);
fclose($datei);
以下代码片段读取文件(其中包含所需的数据,我已经检查过)并将其存储到数据库中:
$blob = fopen("./calendar/temp/tmp_event".$eventrand,'rb');
$stmt = $mysqli->prepare("INSERT INTO calendarobjects(calendardata,lastmodified,[...])
VALUES(?,".time().",[...]");
$stmt->bind_param("b",$blob);
$stmt->execute();
系统执行查询时没有任何错误,但应存储到数据库中的 BLOB 仍为空。有人知道出了什么问题吗?
提前非常感谢您!
致以诚挚的问候
最佳答案
$blob
变量包含文件句柄,而不是二进制内容。
添加以下行以将数据读入变量:
$blob = fopen("./calendar/temp/tmp_event".$eventrand,'rb');
$fsize = filesize("./calendar/temp/tmp_event".$eventrand);
$contents = fread($blob, $fsize); fclose($blob);
$stmt = $mysqli->prepare("INSERT INTO calendarobjects(calendardata,lastmodified,[...])
VALUES(?,".time().",[...]");
$stmt->bind_param("b",$contents);
$stmt->execute();
关于php - 数据库中的 BLOB 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36619096/