search
HomeBackend DevelopmentPHP TutorialPDO如何连接MSSQL和ORACLE数据库?

发现PHP用在传统企业(用MSSQL、ORACLE数据库的企业)真的好少啊。

最近有个项目,需要在开发、生产环境都能部署PHP系统,用PDO对象,要访问MYSQL、MSSQL、ORACLE这几种数据库。

请问该怎么实现,用PHP的PDO在mac、windows、windows server下配置访问这些数据库?mssql版本最低2005,目前用的xampp集成环境。

如果不行,只有换成.net了。。。
__
抱歉,可能我没有完全说清楚。
我试过php手册上的,并且开启了extension=php_mssql.dll,extension=php_pdo_mssql.dll,但是无论使用$dsn = "mssql:host=10.1.1.1;dbname=test";还是$dsn = "dblib:host=10.1.1.1;dbname=test";。
在new pdo的时候,都会提示我错误:Uncaught exception 'PDOException' with message 'could not find driver'。

我在phpinfo那看到pdo drivers里面只有mysql,pgsql,sqlite三项,猜想可能是因为mssql for pdo的驱动没有,但是只搜索到for windows的。
同时,看到在mac下用FreeTDS的(他没有说是xampp还是什么环境),但又需要xcode和另一个什么组件,还要编译,我就在想,难道没有更简洁一点的方法吗?

所以,我想提一个比较完整的问题,希望有这方面实践的高手能够系统地解答一下,同时也方便搜索引擎给sf导流(因为我发现搜索引擎对sf的收录率非常快),以后还有谁碰现类似的问题,不用再去多拼西凑地找方法尝试,因为这真的非常费时间和精力,而且学不到东西。

回复内容:

发现PHP用在传统企业(用MSSQL、ORACLE数据库的企业)真的好少啊。

最近有个项目,需要在开发、生产环境都能部署PHP系统,用PDO对象,要访问MYSQL、MSSQL、ORACLE这几种数据库。

请问该怎么实现,用PHP的PDO在mac、windows、windows server下配置访问这些数据库?mssql版本最低2005,目前用的xampp集成环境。

如果不行,只有换成.net了。。。
__
抱歉,可能我没有完全说清楚。
我试过php手册上的,并且开启了extension=php_mssql.dll,extension=php_pdo_mssql.dll,但是无论使用$dsn = "mssql:host=10.1.1.1;dbname=test";还是$dsn = "dblib:host=10.1.1.1;dbname=test";。
在new pdo的时候,都会提示我错误:Uncaught exception 'PDOException' with message 'could not find driver'。

我在phpinfo那看到pdo drivers里面只有mysql,pgsql,sqlite三项,猜想可能是因为mssql for pdo的驱动没有,但是只搜索到for windows的。
同时,看到在mac下用FreeTDS的(他没有说是xampp还是什么环境),但又需要xcode和另一个什么组件,还要编译,我就在想,难道没有更简洁一点的方法吗?

所以,我想提一个比较完整的问题,希望有这方面实践的高手能够系统地解答一下,同时也方便搜索引擎给sf导流(因为我发现搜索引擎对sf的收录率非常快),以后还有谁碰现类似的问题,不用再去多拼西凑地找方法尝试,因为这真的非常费时间和精力,而且学不到东西。

Windows版PHP内置了Oracle驱动,在ext目录下:
php_oci8.dll
php_oci8_11g.dll
php_pdo_oci.dll
Linux上如果自己编译的话则添加下面的configure配置项,比如:
--with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client/lib
--with-pdo-oci=shared,instantclient,/usr/lib/oracle,11.2
Oracle Instant Client下载地址(60MB):
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

SQL Server Driver for PHP (php_sqlsrv.dll和php_pdo_sqlsrv.dll,仅支持Windows):
http://www.microsoft.com/en-us/download/confirmation.aspx?id=20098
Linux上访问SQL Server可以用unixODBC+FreeTDS
FreeTDS: UNIX/Linux下连接SQL Server和Sybase的驱动.
--with-pdo-dblib=DIR PDO: DBLIB-DB support. DIR is the FreeTDS home directory
unixODBC是数据源管理器,管理由各种数据驱动建立的数据源名称.
FreeTDS是免费的SQL Server/Sybase在UNIX/Linux体系中的驱动程序,
可以由unixODBC建立数据源名称,通过名称访问数据.

所以说PHP的话还是用MySQL简单,因为PHP源代码直接内置了MySQL驱动mysqlnd,基于mysqlnd提供mysqli/pdo_mysql支持.当然了,PHP也内置了SQLite引擎.

http://php.net/manual/zh/ref.pdo-oci.php
http://php.net/manual/zh/ref.pdo-dblib.php


其实我想说的是 php编译忒麻烦了 我一般选个集成整合环境 基本上就是右键菜单一勾的事

@murmur google出来的前几个基本是在stackoverflow上,我也大概浏览了一下,基本都像你这样回答的:丢个php.net的链接,或是微软驱动的链接。
或许是我不懂英文,看不明白吧,如果我英文好,也不上segmentfault了。
呵呵。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment