Jump to content

Update MYSQL from Firebird


radagast
Go to solution Solved by jazzman1,

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
Share on other sites

  • Solution

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.

Edited by jazzman1
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.