mysql通过php在不同的服务器上与mssql通信

时间:2022-10-28 20:59:43

I have mysql on a linux server which I own having CentOS installed in it. I want to fetch data from another windows server having mssql database.

我在linux服务器上有mysql,我自己安装了CentOS。我想从另一个拥有mssql数据库的windows服务器获取数据。

I need to create a php script that can get the values from mssql server and insert it into mysql server.

我需要创建一个php脚本,它可以从mssql服务器获取值并将其插入到mysql服务器。

I have tried installing FreeTDS also PDO but still I am unable to connect (not sure if I have installed it properly). The error messages I get are Could not Connect to the server and drivers not found.

我尝试过安装FreeTDS也是PDO,但是仍然无法连接(不确定是否安装正确)。我得到的错误消息不能连接到服务器和未找到的驱动程序。

How can I check if I have installed freetds and PDO drivers correctly.

如何检查是否正确安装了freetds和PDO驱动程序。

Basic Diagram of what I am trying to do:

我正在尝试做的事情的基本图:

Server A (Mumbai) {Linux Cent OS, FreeTDS and PDO installed} ---------> Server B (Delhi) {Windows, MSSql}

服务器A(孟买){Linux Cent OS, FreeTDS和PDO installed}———> Server B (Delhi) {Windows, MSSql}

I want to get data from Server B to Server A.

我想从服务器B获得数据。

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
62Error 20009 (severity 9):
        Unable to connect: Adaptive Server is unavailable or does not exist
        OS error 110, "Connection timed out"
There was a problem connecting to the server

root@server [~]# tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /usr/local/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 5.0
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no

How can I update TDS version form 5 to 7

如何更新TDS版本表格5至7

Please guide.

请指导。

3 个解决方案

#1


0  

Use ADODB Connection

使用ADODB连接

$conn = new COM ("ADODB.Connection", NULL, CP_UTF8) or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=myServer;UID=myUser;PWD=myPass;DATABASE=myDB";
$conn->open($connStr); //Open the connection to the database

$SQL="SELECT id, .........................";
$res=$conn->execute($SQL);
while (!$res->EOF)  //carry on looping through while there are records
{
    $id=$res->Fields('id')->value;
}

http://php.net/manual/en/class.com.php

http://php.net/manual/en/class.com.php

Now go to Example #2 COM example (2)

现在转到示例#2 COM示例(2)

#2


0  

Well, you can use the mssql select querys, set a variable in php with the result from the mssql query, and then do a mysql insert query to insert it into your database

嗯,您可以使用mssql select querys,用php设置一个变量,其中包含来自mssql查询的结果,然后执行mysql insert查询,将其插入到数据库中

$link = mssql_connect($server, 'sa', 'phpfi');
mssql_select_db('php', $link)
$query = mssql_query('SELECT [id] FROM [php].[dbo].[userlist]');
   while ($row = mssql_fetch_assoc($query)) {
        $row['id']
$con=mysqli_connect("127.0.0.1","root","pass","db");
mysqli_query($con,"INSERT INTO tablname VALUES('$id')");
    }

Give this a try. Of course you have to customize it to fit your needs.

试试这个办法。当然,您必须定制它以满足您的需要。

#3


0  

Configure FreeTDS

配置FreeTDS

This is a perfect tutorial for configuring FreeTDS. Every thing from basic..superb tutorial.

这是配置FreeTDS的完美教程。一切从基础. .极好的教程。

Thanks to Hugo Brown.

多亏乌戈·布朗。

#1


0  

Use ADODB Connection

使用ADODB连接

$conn = new COM ("ADODB.Connection", NULL, CP_UTF8) or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=myServer;UID=myUser;PWD=myPass;DATABASE=myDB";
$conn->open($connStr); //Open the connection to the database

$SQL="SELECT id, .........................";
$res=$conn->execute($SQL);
while (!$res->EOF)  //carry on looping through while there are records
{
    $id=$res->Fields('id')->value;
}

http://php.net/manual/en/class.com.php

http://php.net/manual/en/class.com.php

Now go to Example #2 COM example (2)

现在转到示例#2 COM示例(2)

#2


0  

Well, you can use the mssql select querys, set a variable in php with the result from the mssql query, and then do a mysql insert query to insert it into your database

嗯,您可以使用mssql select querys,用php设置一个变量,其中包含来自mssql查询的结果,然后执行mysql insert查询,将其插入到数据库中

$link = mssql_connect($server, 'sa', 'phpfi');
mssql_select_db('php', $link)
$query = mssql_query('SELECT [id] FROM [php].[dbo].[userlist]');
   while ($row = mssql_fetch_assoc($query)) {
        $row['id']
$con=mysqli_connect("127.0.0.1","root","pass","db");
mysqli_query($con,"INSERT INTO tablname VALUES('$id')");
    }

Give this a try. Of course you have to customize it to fit your needs.

试试这个办法。当然,您必须定制它以满足您的需要。

#3


0  

Configure FreeTDS

配置FreeTDS

This is a perfect tutorial for configuring FreeTDS. Every thing from basic..superb tutorial.

这是配置FreeTDS的完美教程。一切从基础. .极好的教程。

Thanks to Hugo Brown.

多亏乌戈·布朗。