Link to home
Start Free TrialLog in
Avatar of dan_stan
dan_stan

asked on

interbase / mysql php script

Hi,

I originally posted a question in relation to selecting data from an interbase database and then inserting it in to a mysql database.

https://www.experts-exchange.com/questions/28284651/insert-data-from-Firebird-to-mysql.html

So far I am able to insert a single selected value by using the following script -

<?php
include_once 'database_connect.php';
      $dbh = ibase_connect($host, $username, $password);
    $stmt = 'SELECT FIRST 10 CLCTABRE ,CLCTNOM  FROM CLIENT';
    $sth = ibase_query($dbh, $stmt);
    while ($row = ibase_fetch_object($sth)) {
   $newvalues[] = $row->CLCTABRE;
}
    ibase_free_result($sth);
    ibase_close($dbh);
	
$dbh = new PDO('mysql:host=localhost;dbname=swdata', 'root', 'root');

$stmt = $dbh->prepare("INSERT INTO USERDB (keysearch) VALUES (:yourValue)");
$stmt->bindParam('yourValue', $value);

try {
	foreach ($newvalues as $value):
		$stmt->execute();
	endforeach;
} catch (PDOException $e) {
	if ($e->errorInfo[1] != 1062) {
		//silently skip duplicate entries
		echo $e->getMessage();
	}
}
?>

Open in new window


However I want to be able to insert more fields in to my insert script, but am getting an error message.
Warning: Illegal string offset 'value1'
Warning: Illegal string offset 'value2'
Warning: Illegal string offset 'value3'

Can someone please give me a hand resolving this?

<?php
include_once 'database_connect.php';
      $dbh = ibase_connect($host, $username, $password);
    $stmt = 'SELECT FIRST 10 CLCTABRE ,CLCTGROUPE ,CLCTVILLIV FROM CLIENT';
    $sth = ibase_query($dbh, $stmt);
    while ($row = ibase_fetch_object($sth)) {
   $newvalues[] = $row->CLCTABRE;
   $newvalues[] = $row->CLCTGROUPE;
   $newvalues[] = $row->CLCTVILLIV;
}
    ibase_free_result($sth);
    ibase_close($dbh);
	
$dbh = new PDO('mysql:host=localhost;dbname=swdata', 'root', 'root');

$stmt = $dbh->prepare("INSERT INTO USERDB (keysearch ,firstname ,surname) VALUES (:value1, :value2, :value3)");
$stmt->bindParam('value1', $x_variable);
$stmt->bindParam('value2', $y_variable);
$stmt->bindParam('value3', $z_variable);
try {
	foreach ($newvalues as $data):
	$x_variable = $data['value1'];
	$y_variable = $data['value2'];
	$z_variable = $data['value3'];
	$stmt->execute();
endforeach;
} catch (PDOException $e) {
	if ($e->errorInfo[1] != 1062) {
		//silently skip duplicate entries
		echo $e->getMessage();
	}
}
?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What are the lines of code that generate the error messages? The line numbers appear in the error messages, and we would need to see the line of code and the complete message to understand the error.
Avatar of dan_stan
dan_stan

ASKER

sorry my mistake!

Warning: Illegal string offset 'value1' in C:\xampp\htdocs\precious\customer.php on line 22

Warning: Illegal string offset 'value2' in C:\xampp\htdocs\precious\customer.php on line 23

Warning: Illegal string offset 'value3' in C:\xampp\htdocs\precious\customer.php on line 24
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray, that worked perfectly, thanks for your help!
PS I'm about to post another question regarding this scrip!
Great! Thanks for the points and thanks for using EE, ~Ray