Jump to content

Update MYSQL from Firebird


radagast

Recommended Posts

Good Day 

 

Please could someone be so gracious as to help me with the following problem.

 

I am wanting to update a MYSQL database from a Firebird database.

 

 I have tested connecting to both databases individually which works fine, it is just when I put the code together it does not work.

 

Below is the code

//Firstly I connect to the MYSQL database to see what needs to updated
      
 mysql_connect("localhost", "database", "password") or die(mysql_error());
 mysql_select_db("database") or die(mysql_error());

$check = "SELECT * FROM table WHERE blah != ''";

$result = mysql_query($check)
or die ("Error in query: $check. " . mysql_error());
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))

 
{
$blah = $row->blah;

// Then I connect to the Firebird database to get the info

$dsndb = 'host';
$userdb = 'user';
$passdb = 'password'; 
try {  
    $dbh = new PDO($dsndb, $userdb, $passdb);
               
   $sth = ("SELECT * from table WHERE blah = '$blah'");


  foreach ($dbh->query($sth) as $row)
   
   {

//Then I update the MYSQL database from the Firebird database info

$sql = "UPDATE table SET field1 = 'field1', field2 = 'field2', field3 = 'field3' WHERE blah = '$blah'";

$update=mysql_query($sql) or die(mysql_error());

     }

}

  } 
}

Your assistance will be greatly appreciated.

 

 

     
Link to comment
https://forums.phpfreaks.com/topic/290532-update-mysql-from-firebird/
Share on other sites

Try to use PDO only - next works for me. I'm not sure whether it's possible to use two different database libraries on the same document event the drivers are connecting to the same db server....turn php errors on checkout for actual errors.

<?php

ini_set('display_startup_errors',1);

ini_set('display_errors',1);

error_reporting(-1);

$user = 'SYSDBA';

$pass = 'masterdba';

$dbh = new PDO("firebird:dbname=127.0.0.1:/var/firebirddata/new.fdb;charset=utf8", $user, $pass);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$username = 'lxc';
     
$password = 'password';
     
$dbh1 = new PDO('mysql:dbname=test;host=::1;charset=utf8', $username, $password);
    
$dbh1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Don't use mysql library for new development.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.