//connect to mssql server and select database
mssql_pconnect($mshostname,$msusername,$mspassword) OR DIE("MSSQL Database connection failed.");
mssql_select_db($msdbName) or DIE("MSSQL DB unavailable");
//query to get required fields from finesse
$sql_out = "SELECT * FROM table01 ";
//run the query on the finesse database
$query = mssql_query($sql_out);
printf("<table border=1 width=100%%>");
//loop to get each row from mssql
while ($rs = mssql_fetch_array($query)) {
<?
//set variables for connecting to mssql
$mshostname = "localhost";
$msusername = "sa";
$mspassword = "123456";
$msdbName = "mydb01";
//set variables for connecting to mysql
$myhostname = "localhost";
$myusername = "root";
$mypassword = "password";
$mydbname = "mydb02";
//connect to mssql server and select database
mssql_pconnect($mshostname,$msusername,$mspassword) OR DIE("MSSQL Database connection failed.");
mssql_select_db($msdbName) or DIE("MSSQL DB unavailable");
//query to get required fields from finesse
$sql_out = "SELECT * FROM table01 ";
//run the query on the finesse database
$query = mssql_query($sql_out);
printf("<table border=1 width=100%%>");
//connect to mysql server, select db and insert row
$conn = mysql_pconnect($myhostname,$myusername,$mypassword);
mysql_select_db('mydb02');
//Check table is exit then drop table
$sql = 'DROP TABLE IF EXISTS `table02`';
mysql_query( $sql, $conn ) or die ("ลบฐานข้อมูลไม่ได้");
//Then drop table and Create table
$sql = 'CREATE TABLE `table02` (
`id` INT( 4 ) NOT NULL,
`username` VARCHAR( 50 ) NOT NULL,
`lastname` VARCHAR( 50 ) NOT NULL,
PRIMARY KEY ( `id` )
)';
$result = mysql_query( $sql, $conn );
//Check Result from Query
if($result){
echo "สร้างตางรางข้อมูลเรียบร้อยแล้ว";
echo "<br>";
}else{
echo "ไม่สามารถส้รางตารางข้อมูลได้";
}
//loop to get each row from mssql
while ($rs = mssql_fetch_array($query))
{
$rs_id=$rs["id"];
$rs_username=$rs["username"];
$rs_lastname=$rs["lastname"];
// Insert Data to table
$sql_in = "INSERT INTO table02 (id,username,lastname) VALUES ('$rs_id','$rs_username','$rs_lastname')";
$result2 = mysql_query($sql_in, $conn);
//Check Result from Query
if (! $result2) {
echo ("ไม่สามารถบันทึกลงตารางข้อมูลได้");
}else{