当前位置:网站首页>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
边栏推荐
- Common interview questions of operating system:
- My raspberry PI zero 2W tossing notes record some problems encountered and solutions
- What is the role of the full connection layer?
- C语言超全学习路线(收藏让你少走弯路)
- 8.5 concise implementation of cyclic neural network
- Difference between like and regexp
- 深度学习调参的技巧
- Openfaas practice 4: template operation
- How to use OCR in 5 minutes
- 免费在upic中设置OneDrive或Google Drive作为图床
猜你喜欢
Mysql database explanation (8)
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
For 22 years, you didn't know the file contained vulnerabilities?
群体智能自主作业智慧农场项目启动及实施方案论证会议
T2 iCloud日历无法同步
API gateway / API gateway (II) - use of Kong - load balancing
Nuxt project: Global get process Env information
Lotus DB design and Implementation - 1 Basic Concepts
Have you learned the basic operation of circular queue?
随机推荐
setcontext getcontext makecontext swapcontext
adobe illustrator 菜单中英文对照
Ffmpeg installation error: NASM / yasm not found or too old Use --disable-x86asm for a clipped build
API gateway / API gateway (II) - use of Kong - load balancing
Byte interview programming question: the minimum number of K
A series of problems about the best time to buy and sell stocks
MySQL installation process (steps for successful installation)
免费在upic中设置OneDrive或Google Drive作为图床
X509 certificate cer format to PEM format
Mysql database explanation (10)
js——实现点击复制功能
asp. Net method of sending mail using mailmessage
win10 任务栏通知区图标不见了
My raspberry PI zero 2W toss notes to record some problems and solutions
深度学习——超参数设置
How to use OCR in 5 minutes
Share 3 tools, edit 5 works at home and earn more than 400
Leetcode学习计划之动态规划入门day3(198,213,740)
Openstack command operation
Knn,Kmeans和GMM