使用pdo_odbc

时间:2019-03-16 17:16:09

标签: php mysql odbc

我可以使用以下脚本通过ODBC / SSL(see my post)连接到MySQL数据库:

ini_set ('error_reporting', E_ALL);
ini_set ('display_errors', '1');
error_reporting (E_ALL|E_STRICT);

$user = "odbcmmm";
$pass = "999999999";

$connection = "Driver={mysql537};Server=99.99.199.199;Database=db_name;UID=odbc_db_name;PWD=password;sslca=/etc/mysql/ssl/c1.pem;sslkey=/etc/mysql/ssl/ck.pem;sslcapath=/etc/mysql/ssl/;sslcert=/etc/mysql/ssl/cc.pem";

$con = odbc_connect($connection, $user, $pass);

$sql="SELECT Id from stk_item"; 
$rs=odbc_exec($con,$sql);

if (!$rs)   {
exit("Error in SQL");
}

但是,当我尝试使用下面的脚本创建PDO对象时,出现错误:

  

SQLSTATE [IM002] SQLDriverConnect:0 [unixODBC] [驱动程序管理器]未找到数据源名称,并且未指定默认驱动程序**

<?php
ini_set ('error_reporting', E_ALL);
ini_set ('display_errors', '1');
$pass = "pass";

try {

$connection = new PDO("odbc:mysql537;Server=99.99.199.199;Database=db1;UID=user1;PWD=pwd1;sslca=/etc/mysql/ssl/c1.pem;sslkey=/etc/mysql/ssl/ck.pem;sslcapath=/etc/mysql/ssl/;sslcert=/etc/mysql/ssl/cc.pem");

error_reporting (E_ALL|E_STRICT);


} catch (PDOException $exception) {
  echo $exception->getMessage();
  exit;

}

当我如下更改代码时,错误是:

  

无效的数据源名称

<?php

ini_set ('error_reporting', E_ALL);
ini_set ('display_errors', '1');
error_reporting (E_ALL|E_STRICT);

$user = "user";
$pass = "pass";

try {

$connection = new PDO("Driver={mysql537};Server=99.99.199.199;Database=db1;UID=user1;PWD=pwd1;sslca=/etc/mysql/ssl/c1.pem;sslkey=/etc/mysql/ssl/ck.pem;sslcapath=/etc/mysql/ssl/;sslcert=/etc/mysql/ssl/cc.pem");

} catch (PDOException $exception) {
  echo $exception->getMessage();
  exit;

}

我知道PDO ODBC驱动程序是通过phpinfo安装的,因此我必须在某个地方弄乱 PDO ODBC 连接语法。任何帮助发现我的错误的方法,深表感谢。谢谢。

0 个答案:

没有答案