php - 如何建立 Pervasive PDO PHP 连接
问题描述
我正在尝试建立与我的作品 Pervasive SQL 数据库的连接。我试过使用 odbc_connect (没用),但有人告诉我 PDO 更容易更好(HA,也没有用)。这是我的连接字符串
$dbh = new PDO("odbc:Driver={Pervasive ODBC Client Interface};ServerName=192.168.43.19;dbq=GLOBALTST");
我试过 odbc:DSNname ( https://www.php.net/manual/en/ref.pdo-odbc.connection.php )、ODBC:servername (ip and hostname) 和 odbc:databasename。没有任何效果。这是我得到的错误:
Fatal error: Uncaught PDOException: SQLSTATE[IM003] SQLDriverConnect: 160 Specified driver could not be loaded due to system error 1114: A dynamic link library (DLL) initialization routine failed. (Pervasive ODBC Client Interface, C:\PSQL\bin\w3odbcci.dll). in C:\inetpub\wwwroot\default.php:4 Stack trace: #0 C:\inetpub\wwwroot\default.php(4): PDO->__construct() #1 {main} thrown in C:\inetpub\wwwroot\default.php on line 4
它正在寻找的 DLL 实际上位于它所引用的位置。据我所知,它没有问题。服务器上的 ODBC 配置正确,我可以连接到 PSQL 控制中心的数据库。任何人都可以帮助确定我的问题或指向适用于 odbc_connect 或 PDO 的连接字符串吗?
解决方案
此代码在 Windows 机器上使用 PSQL v11 64 位 ODBC、PHP 7.2 64 位对我有用。
<?php
try {
// Connect to the data source
//$dbh = new PDO($dsn);
$dbh = new PDO("odbc:Driver={Pervasive ODBC Interface};ServerName=192.168.43.19;dbq=demodata");
$stmt = $dbh->prepare('SELECT * FROM class');
// Execute the prepared statement for each name in the array
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$numResults = count($result);
echo ('<b>Total Results: </b> ' . $numResults . '<br>');
if ($numResults > 0) {
// Output the table header
echo '<table><tr>';
foreach ($result[0] as $fieldName=>$value) {
echo '<th>' . htmlspecialchars($fieldName) . '</th>';
}
echo '</tr>';
// Now output all the results
foreach($result as $row) {
echo '<tr>';
foreach ($row as $fieldName=>$value) {
echo '<td>' . htmlspecialchars($value) . '</td>';
}
echo '</tr>';
}
// Close the table
echo '</table>';
} else {
echo 'No results';
}
// Close statement and data base connection
$stmt = NULL;
$dbh = NULL;
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>
推荐阅读
- html - HTML CSS 图片库不使用 Auto 或 Stretch 制作正方形
- javascript - 纯 JavaScript 仅检测 Ctrl+Q 快捷键
- angular - 即使启用 withCredentials 选项 angular + electronjs 也会忽略 set-cookie 标头
- video - 使用 ffmpeg 或 ffprobe 获取视频的像素位深度
- node.js - 无需注册应用即可进行 Microsoft-Graph API 调用
- python - 是否可以在函数中传递 for 循环?
- jestjs - Jest 是否支持stealjs
- javascript - TypeError: $scope.lstLaptop.push 不是函数
- python - 如何使用 django(查询)在我的 html 中显示更多对象
- python-3.x - PySimpleGUI - 窗口更改时不显示背景