[英]mysql communicate with mssql on different server via php
我在自己安裝了CentOS的Linux服務器上安裝了mysql。 我想從另一個具有mssql數據庫的Windows服務器中獲取數據。
我需要創建一個可以從mssql服務器獲取值並將其插入mysql服務器的php腳本。
我嘗試過同時安裝FreeTDS和PDO,但仍然無法連接(不確定是否已正確安裝)。 我收到的錯誤消息是“無法連接到服務器並且找不到驅動程序”。
如何檢查是否正確安裝了freetds和PDO驅動程序。
我正在嘗試做的基本圖:
服務器A(孟買){安裝了Linux Cent OS,FreeTDS和PDO} --------->服務器B(德里){Windows,MSSql}
我想要從服務器B到服務器A的數據。
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
如何將TDS版本表5更新為7
請指導。
好吧,您可以使用mssql select查詢,使用mssql查詢的結果在php中設置一個變量,然后執行mysql插入查詢以將其插入數據庫中
$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')");
}
試試看。 當然,您必須對其進行自定義以滿足您的需求。
使用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/zh/class.com.php
現在轉到Example#2 COM示例(2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.