php - How to read from Firebird database and insert the data into MSSQL database? -


i want select columns firebird database , insert them in mssql database tables.

when read table firebird represent need in localhost, when want insert data mssql inserts last record. don't know cause this, , it's first time try idea.

would tell me goes wrong?

this php code:

<?php $host = 'localhost:c:\firebird.fdb';  $username='';  $password='';  $dbh = ibase_connect($host, $username, $password); $stmt = "select * tweekday"; $sth = ibase_query($dbh, $stmt); while ($row = ibase_fetch_object($sth)) { $r1 = $row->code; $r2 = $row->dayname;     echo $r1 ." ". $r2  . "\n";     echo "</br>"; } ibase_close($dbh);  /**********************************************/  $host = "servername\instancename"; $connectioninfo = array( "database"=>"mssqldatabase", "uid"=>"", "pwd"=>""); $conn = sqlsrv_connect( $host, $connectioninfo); if( $conn === false ) {     die( print_r( sqlsrv_errors(), true)); } echo "</br>";   $tsql =  "insert [accesscard].[dbo].[weekday] (dayid,dayn) values ('$r1','$r2')";  $stmt = sqlsrv_query( $conn, $tsql);   if ( $stmt === false )    {          die( print_r( sqlsrv_errors(), true));     }   while( $obj = sqlsrv_fetch_object( $stmt ,  sqlsrv_fetch_assoc) ) {       echo $obj->dayid ."&nbsp ". $obj->dayn . "<br />"; } sqlsrv_free_stmt( $stmt);   sqlsrv_close( $conn); ?> 

when run code, shows in local host :pic1 , when open mssql database table have:pic2 seems insert last value of $r1 $r2.

and when use code:

<?php $host = 'localhost:c:\firebird.fdb';  $username='';  $password='';  $dbh = ibase_connect($host, $username, $password); $stmt = "select * tweekday"; $sth = ibase_query($dbh, $stmt); while ($row = ibase_fetch_object($sth)) { $r1 = $row->code; $r2 = $row->dayname;     echo $r1." ". $r2  . "\n";     echo "</br>"; } ibase_close($dbh);  /**********************************************/  $host = "servername\instancename"; $connectioninfo = array( "database"=>"accesscard", "uid"=>"", "pwd"=>""); $conn = sqlsrv_connect( $host, $connectioninfo); if( $conn === false ) {     die( print_r( sqlsrv_errors(), true)); } echo "</br>";   ($ridx = 0; $ridx < count($r1); $ridx++) { // each $r array value    $tsql =  "insert [accesscard].[dbo].[weekday] (dayid,dayn) values ('$r1[$ridx]','$r2[$ridx]')";    $stmt = sqlsrv_query( $conn, $tsql);    if ( $stmt === false )    {          die( print_r( sqlsrv_errors(), true));       } } // end of insert loop   sqlsrv_free_stmt( $stmt);   sqlsrv_close( $conn); ?> 

this show in database:pic3

$r1 should array, in $r1[] = $row->code; $r2' obviously. change sqlserver insert accordingly. don't have sql server installed here cannot provide tested code. here sql server code...

$host = "servername\instancename"; $connectioninfo = array( "database"=>"mssqldatabase", "uid"=>"", "pwd"=>""); $conn = sqlsrv_connect( $host, $connectioninfo); if( $conn === false ) {     die( print_r( sqlsrv_errors(), true)); } echo "</br>";   ($ridx = 0; $ridx < count($r1); $ridx++) { // each $r array value    $tsql =  "insert [accesscard].[dbo].[weekday] (dayid,dayn) values ('$r1[$ridx]','$r2[$ridx]')";     $stmt = sqlsrv_query( $conn, $tsql);     if ( $stmt === false )    {          die( print_r( sqlsrv_errors(), true));       }  } // end of insert loop    sqlsrv_free_stmt( $stmt);   sqlsrv_close( $conn); ?> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -