当前位置:网站首页>PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
2022-04-23 15:25:00 【allway2】
<?php
$hostname = "localhost";
$database = "db";
$username = "root";
$password = "root";
try {
$pdo = new PDO("odbc:Driver={MySQL ODBC 3.51 Driver};host=$hostname;database=$database", $username, $password);
} catch (PDOException $e) {
echo $e->getMessage();
}
$arrFiles = array();
$iterator = new FilesystemIterator("InputFiles");
foreach ($iterator as $entry) {
$arrFiles[] = $entry->getFilename();
echo ( $entry->getFilename());
echo ( $entry->getPathname());
$blob = fopen($entry->getPathname(), 'rb');
$sql = "INSERT INTO gallery(name,image) VALUES(:name,:image)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':name', $entry->getFilename());
$stmt->bindParam(':image', $blob, PDO::PARAM_LOB);
$stmt->execute();
}
?>
<?php
$hostname = "localhost";
$database = "db";
$username = "root";
$password = "root";
try {
$pdo = new PDO("odbc:Driver={MySQL ODBC 3.51 Driver};host=$hostname;database=$database", $username, $password);
} catch (PDOException $e) {
echo $e->getMessage();
}
$sql = "SELECT name,image FROM gallery";
$stmt = $pdo->query($sql);
while ($row = $stmt->fetch()) {
$filehandle = fopen("DownLoadFiles/" . $row[name], 'wb');
fwrite($filehandle, $row[image]);
fclose($filehandle);
}
?>
版权声明
本文为[allway2]所创,转载请带上原文链接,感谢
https://blog.csdn.net/allway2/article/details/124361888
边栏推荐
- JUC学习记录(2022.4.22)
- Differential privacy (background)
- 深度学习——超参数设置
- Detailed explanation of C language knowledge points - data types and variables [2] - integer variables and constants [1]
- fatal error: torch/extension.h: No such file or directory
- Adobe Illustrator menu in Chinese and English
- My raspberry PI zero 2W toss notes to record some problems and solutions
- Three uses of kprobe
- Openfaas practice 4: template operation
- Do keyword search, duplicate keyword search, or do not match
猜你喜欢
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
Have you learned the basic operation of circular queue?
字节面试 transformer相关问题 整理复盘
Five data types of redis
深度学习——超参数设置
Thinkphp5 + data large screen display effect
Mysql连接查询详解
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
How to design a good API interface?
今日睡眠质量记录76分
随机推荐
如何设计一个良好的API接口?
Tun equipment principle
The life cycle of key value in redis module programming
免费在upic中设置OneDrive或Google Drive作为图床
Three uses of kprobe
机器学习——逻辑回归
Nacos程序连接MySQL8.0+ NullPointerException
8.5 concise implementation of cyclic neural network
Krpano panorama vtour folder and tour
js——實現點擊複制功能
Basic operation of circular queue (Experiment)
Redis cluster principle
After time judgment of date
激活函数的优缺点和选择
Mysql database explanation (VII)
Precautions for use of dispatching system
C语言超全学习路线(收藏让你少走弯路)
asp. Net method of sending mail using mailmessage
函数(第一部分)
On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)