当前位置:网站首页>PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
2022-04-23 15:26: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://yzsam.com/2022/04/202204231525131193.html
边栏推荐
- Krpano panorama vtour folder and tour
- YML references other variables
- 让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
- Analysis of common storage types and FTP active and passive modes
- Wechat applet customer service access to send and receive messages
- Tun model of flannel principle
- Fill in the next right node pointer II of each node [classical hierarchy traversal | regarded as linked list]
- 我的 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
- About UDP receiving ICMP port unreachable
- 免费在upic中设置OneDrive或Google Drive作为图床
猜你喜欢
Mysql连接查询详解
Openstack command operation
How to design a good API interface?
Openfaas practice 4: template operation
About UDP receiving ICMP port unreachable
Machine learning - logistic regression
Redis master-slave synchronization
Mysql database explanation (IX)
Set onedrive or Google drive as a drawing bed in upic for free
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
随机推荐
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
Elk installation
UML learning_ Day2
Thinkphp5 + data large screen display effect
Detailed explanation of kubernetes (XI) -- label and label selector
Mysql database explanation (8)
【thymeleaf】处理空值和使用安全操作符
Redis master-slave synchronization
On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)
Llvm - generate if else and pH
G007-HWY-CC-ESTOR-03 华为 Dorado V6 存储仿真器搭建
Async void caused the program to crash
JUC learning record (2022.4.22)
Common interview questions of operating system:
Hj31 word inversion
Fill in the next right node pointer II of each node [classical hierarchy traversal | regarded as linked list]
Have you really learned the operation of sequence table?
Nacos程序连接MySQL8.0+ NullPointerException
My raspberry PI zero 2W toss notes to record some problems and solutions
Introduction to distributed transaction Seata