将 PHP 代码从 MSSQL 迁移到 MySQL [英] Migrate PHP code from MSSQL to MySQL

查看:55
本文介绍了将 PHP 代码从 MSSQL 迁移到 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个连接到 MSSQL 以获取其数据的大型 Web 应用程序.这个网络应用程序有数百个 .php 文件.我有一个新客户,他不想使用 MSSQL,而是想使用 MySQL.

I currently have a large web application that connects to MSSQL to fetch its data. This web app has hundreds of .php files. I have a new customer, and he doesn't want to use MSSQL, but MySQL instead.

我搜索并找到了很多关于如何迁移数据的文章.但这不是我的问题.我知道该怎么做,此外我们将从一个空白数据库开始,除了一些默认目录.

I've searched and found lots of articles on how to migrate data. But that's not my problem. I know how to do that, besides we'll be starting with a blank database, except for a few default catalogs.

我需要知道的是是否有一种方法可以将 mssql_query 代码自动更改为 mysqli 代码.例如:

What I need to know is if there's a way to automatically change the mssql_query code to mysqli code. For example:

$SqlText = 'SELECT a, b, c FROM table WHERE x=y';
if (!$result = mssql_query($SqlText) {
   die('Error');
}
while ($row = mssql_fetch_assoc($result) {
   echo '<td>' . $row['a'] . '</td>';
   echo '<td>' . $row['b'] . '</td>';
   echo '<td>' . $row['c'] . '</td>';
}

变成类似:

$SqlText = 'SELECT a, b, c FROM table WHERE x=y';
if (!$result = mssqli_query($db, $SqlText) {
   die('Error');
}
while ($row = mssqli_fetch_assoc($result) {
   echo '<td>' . $row['a'] . '</td>';
   echo '<td>' . $row['b'] . '</td>';
   echo '<td>' . $row['c'] . '</td>';
}

此外,如您所见,我使用的是旧版 mssql_query 代码,新版本的 PHP 甚至不支持该代码.是否至少有一个工具可以将我的代码从 mssql_query 更改为新版本的 sqlserv_query 类型的命令?

Besides, as you can see, I was using the old mssql_query code which is not even supported in the newer versions of PHP. Is there at least a tool that could change my code from mssql_query into the new version of sqlserv_query type of commands?

非常感谢任何帮助.

推荐答案

我认为没有完全自动的方法.因为 MySQL 有 'LIMIT',例如 MSSQL 有 'TOP'.当然,这不一定是问题,但我不确定复杂的 MSSQL 查询是否会 1:1 转换为 MySQL.

I do not think there is a totally automatic way. Because MySQL has 'LIMIT' for example where MSSQL has 'TOP'. Of course that would not have to be a problem but I am not sure if complex MSSQL queries would translate 1:1 to MySQL.

并建议您使用 `` 符号向 MySql 指出它是数据库、表或列名的成员.示例:

And suggest you use the `` signs to point out to MySql it is a member of a databaes, table or column name. Example:

$SqlText = 'SELECT a, b, c FROM table WHERE x=y';

将更改为

$SqlText = 'SELECT `a`, `b`, `c` FROM `table` WHERE `x`=y';

现在您可以进行像

'SELECT `select` FROM `datetime` WHERE `limit` = 1'

否则的话,select、datetime 和 limit 会干扰 MySql 语法.

Otherwise the words, select, datetime and limit would interfere with MySql syntax.

这篇关于将 PHP 代码从 MSSQL 迁移到 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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