PHP,Microsoft SQL Server(MSSQL)和IIS:使用ODBC连接和查询

I was recently thrown a real curveball of a project. Instead of using a fresh MySQL database to pull information from, the customer required that we pull information from their new Microsoft SQL Server 2005 server. This isn't the most desired method of PHP->Database interactivity but that's what the project called for and that's what I needed to do. Here's how to get things going.

最近,我被一个项目吸引了。 客户要求我们从其新的Microsoft SQL Server 2005服务器中提取信息,而不是使用新MySQL数据库来提取信息。 这不是PHP-> Database交互性的最理想方法,但这就是项目所需要的,而这正是我需要做的。 这是解决问题的方法。

从PHP连接到Microsoft SQL Server 2005 (Connecting to Microsoft SQL Server 2005 from PHP)


// the "driver" first
$virtual_dsn = 'DRIVER={SQL Server};SERVER=database.domain.org,45277;DATABASE=MyDatabase';
$connection = odbc_connect($virtual_dsn,'Username','Password') or die('ODBC Error:: '.odbc_error().' :: '.odbc_errormsg().' :: '.$virtual_dsn);


选择哪个数据库 (Choose Which Database)

odbc_exec($connection,'USE MYDB');

执行查询 (Executing a Query)

$result = odbc_exec($connection, 'SELECT FirstName FROM Names');

使用查询结果 (Using the Query Result)

$first_name = odbc_result($result, 'FirstName')

查询带有空格的表和列 (Querying Tables and Columns with Spaces)


// use brackets [] for tables and colums with spaces
$result = odbc_exec($connection, 'SELECT [First Name] FROM [Names Table]');


Like I said, while this isn't the most desirable setup in the world, it will do. Big ups to Hostway for their help in configuring the server; they provided everything we needed.

就像我说的那样,虽然这不是世界上最理想的设置,但它会做到。 Hostway非常感谢他们在配置服务器方面的帮助; 他们提供了我们所需的一切。

To learn more about the ODBC functions, visit PHP.net

要了解有关ODBC函数的更多信息,请访问PHP.net

翻译自: https://davidwalsh.name/php-microsoft-sql-server-mssql-iis-connect-query-odbc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值