当前位置:网站首页>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
边栏推荐
- Error: unable to find remote key "17f718f726"“
- 【Leetcode-每日一题】安装栅栏
- redis-shake 使用中遇到的错误整理
- 让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
- Lotus DB design and Implementation - 1 Basic Concepts
- Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
- Application of skiplist in leveldb
- Mysql database explanation (VII)
- Mysql database explanation (IX)
- Have you really learned the operation of sequence table?
猜你喜欢
Squid agent
深度学习——超参数设置
asp. Net method of sending mail using mailmessage
自主作业智慧农场创新论坛
Mysql database explanation (8)
Sword finger offer (1) -- for Huawei
Detailed explanation of redirection and request forwarding
电脑怎么重装系统后显示器没有信号了
Byte interview programming question: the minimum number of K
8.2 text preprocessing
随机推荐
Share 3 tools, edit 5 works at home and earn more than 400
Grep was unable to redirect to the file
Collation of errors encountered in the use of redis shake
regular expression
Mysql database explanation (8)
Baidu written test 2022.4.12 + programming topic: simple integer problem
Crawling fragment of a button style on a website
Do keyword search, duplicate keyword search, or do not match
什么是CNAS认证?CNAS认可的软件测评中心有哪些?
Deep learning - Super parameter setting
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
About UDP receiving ICMP port unreachable
Llvm - generate for loop
免费在upic中设置OneDrive或Google Drive作为图床
MySQL query library size
[thymeleaf] handle null values and use safe operators
今日睡眠质量记录76分
移动app测试如何进行?
js——实现点击复制功能
MySQL Basics