PDO如何连接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了。
呵呵。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.
