且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP PDO ODBC连接

更新时间:2023-02-23 10:00:13

如果您已经定义了ODBC并已存储了密码,则可以简单地与

if you already have the ODBC defined and have a stored password, you can simply connect with

$conn = new PDO("odbc:DSN_NAME") 

其中DSN_NAME是ODBC数据源的实际名称,可以是MySQL,SQL Server或DB2.

where DSN_NAME is the actual name of your ODBC datasource, be it MySQL, SQL Server or DB2.

您可以使用以下方法测试连接:

You can test your connection with the following:

try{
    $conn = new PDO ("odbc:DSN_NAME");

    die(json_encode(array('outcome' => true)));
}
catch(PDOException $ex){
     die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
}