mysqli命令也可用于mssql服务器吗? [英] is mysqli command also avaible for use in mssql server?

查看:56
本文介绍了mysqli命令也可用于mssql服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然没有尝试使用mysqli,因为我想首先知道它是否可以用于mssql服务器,因为我仍计划购买mssql服务器的许可证

I still haven't tried using mysqli, because i wanna know first if it can be used using mssql server because I'm still planning to buy a license of mssql server

推荐答案

Mysqli特定于MySQL.如果要访问MSSQL,建议您使用PDO,这是一个PHP函数集/语句,可以使用每种类型的驱动程序来一般访问各种数据库类型.要使用PDO连接到MSSQL数据库,首先需要SQLSRV(驱动程序),可以从Microsoft

Mysqli is specific to MySQL. If you want access to MSSQL, I'd recommend you use PDO, a PHP function set/statement which can generically access various database types using drivers for each type. To connect to a MSSQL database using PDO, you first need SQLSRV, the driver, which you can download from Microsoft here. To connect, you would use the following:

$handle = new PDO("sqlsrv:Server=$server;Database=$database", $username, $password);

要查询:

$queryRef = $handle->query($query);

要读取结果,请将$results声明为二维关联数组,第一个是结果编号,第二个是列名称:

To read results, declaring $results as a two-dimensional associative array, the first being the result number, the second being the column name:

$results = $queryRef->fetchAll(PDO::FETCH_ASSOC);

所以$results[3]['id']将是第三个结果的列"id"的值.

So $results[3]['id'] would be the value of the column 'id' of the third result.

您可以在PHP文档页面上找到有关PDO的更多示例这里. PDO的优点在于,您可以对不同的数据库使用相同的代码,只需要更改驱动程序,甚至可能更改查询即可.

You can find more examples on the PHP documentation page for PDO here. The great thing about PDO is that you can use the same code for different databases, you just need to change the driver, and possibly the queries.

这篇关于mysqli命令也可用于mssql服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆