当前位置:网站首页>通過 PDO ODBC 將 PHP 連接到 MySQL
通過 PDO ODBC 將 PHP 連接到 MySQL
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);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id,name,city FROM mytable";
$stmt = $pdo->query($sql);
while ($row = $stmt->fetch()) {
print( $row[0] . "-" . $row[1] . "-" . $row[2] . "\r\n");
}
} catch (PDOException $e) {
echo $e->getMessage();
exit;
}
# close the connection
$dbh = null;
?>
版权声明
本文为[allway2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231525131224.html
边栏推荐
猜你喜欢

Functions (Part I)

TLS / SSL protocol details (28) differences between TLS 1.0, TLS 1.1 and TLS 1.2

Five data types of redis

今日睡眠质量记录76分

机器学习——逻辑回归

我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法

木木一路走好呀

Have you really learned the operation of sequence table?

How to use OCR in 5 minutes
![Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]](/img/07/c534238c2b5405bbe4655e51cfee51.png)
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
随机推荐
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
Explanation of redis database (III) redis data type
Redis master-slave synchronization
C语言超全学习路线(收藏让你少走弯路)
如果conda找不到想要安装的库怎么办PackagesNotFoundError: The following packages are not available from current
Three uses of kprobe
The life cycle of key value in redis module programming
The wechat applet optimizes the native request through the promise of ES6
Share 3 tools, edit 5 works at home and earn more than 400
Introduction to distributed transaction Seata
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
adobe illustrator 菜單中英文對照
木木一路走好呀
Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system
SSH connects to the remote host through the springboard machine
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
买卖股票的最佳时机系列问题
For 22 years, you didn't know the file contained vulnerabilities?
Advanced version of array simulation queue - ring queue (real queuing)
Baidu written test 2022.4.12 + programming topic: simple integer problem