当前位置:网站首页>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
边栏推荐
- Explanation of redis database (III) redis data type
- Tun model of flannel principle
- Three uses of kprobe
- Modify the default listening IP of firebase emulators
- UML学习_day2
- Machine learning - logistic regression
- MySQL InnoDB transaction
- SSH connects to the remote host through the springboard machine
- Detailed explanation of MySQL connection query
- js——實現點擊複制功能
猜你喜欢
Mysql database explanation (VII)
Sword finger offer (2) -- for Huawei
Machine learning - logistic regression
Openstack command operation
今日睡眠质量记录76分
Openfaas practice 4: template operation
win10 任务栏通知区图标不见了
Set onedrive or Google drive as a drawing bed in upic for free
How to design a good API interface?
自主作业智慧农场创新论坛
随机推荐
JS - implémenter la fonction de copie par clic
Share 3 tools, edit 5 works at home and earn more than 400
Do keyword search, duplicate keyword search, or do not match
Leetcode学习计划之动态规划入门day3(198,213,740)
T2 iCloud日历无法同步
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
fatal error: torch/extension.h: No such file or directory
深度学习——超参数设置
Kubernetes详解(九)——资源配置清单创建Pod实战
Kubernetes详解(十一)——标签与标签选择器
Summary of interfaces for JDBC and servlet to write CRUD
【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
8.4 realization of recurrent neural network from zero
UML学习_day2
How to upload large files quickly?
The wechat applet optimizes the native request through the promise of ES6
Elk installation
MySQL Basics
Little red book timestamp2 (2022 / 04 / 22)
函数(第一部分)