当前位置:网站首页>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
边栏推荐
- Do keyword search, duplicate keyword search, or do not match
- Little red book timestamp2 (2022 / 04 / 22)
- About UDP receiving ICMP port unreachable
- 【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
- setcontext getcontext makecontext swapcontext
- PSYNC synchronization of redis source code analysis
- Llvm - generate if else and pH
- 激活函数的优缺点和选择
- Leetcode学习计划之动态规划入门day3(198,213,740)
- js——实现点击复制功能
猜你喜欢
激活函数的优缺点和选择
Knn,Kmeans和GMM
Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system
Nuxt project: Global get process Env information
8.4 realization of recurrent neural network from zero
Byte interview programming question: the minimum number of K
Introduction to distributed transaction Seata
Reptile exercises (1)
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
Functions (Part I)
随机推荐
Differential privacy (background)
Little red book timestamp2 (2022 / 04 / 22)
C语言超全学习路线(收藏让你少走弯路)
电脑怎么重装系统后显示器没有信号了
MySQL sync could not find first log file name in binary log index file error
Nuxt project: Global get process Env information
Mysql database explanation (IX)
Flink datastream type system typeinformation
Summary of interfaces for JDBC and servlet to write CRUD
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
8.5 concise implementation of cyclic neural network
js——實現點擊複制功能
Openstack command operation
Llvm - generate addition
Llvm - generate if else and pH
MySQL InnoDB transaction
Sword finger offer (2) -- for Huawei
Precautions for use of dispatching system
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
After time judgment of date