If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Announcement

Collapse

No announcement yet.

How can I use insert into reading data from MsAccess db for inserting into mySQL ?

Comment

Based on your suggestion I set main connection of Blank application to myQSL and I did the query to Ms Access defining the connection as following:
I can't use the MsAccess query into the INSERT INTO becouse I can't define the connection there.
So first I did the MsAccess query obtainign an array of all values.

$sql_customers="SELECT Q_Customers.CodAnag AS CustomerID, \"Q_Customers.Ragione sociale\" AS CompanyName, Q_Customers.NomeContatto AS ContactName, Q_Customers.Indirizzo AS Address, LocalitÓ AS City, Q_Customers.Provincia AS Region, Q_Customers.CAP AS PostalCode, Q_Customers.Nazione AS Country, Q_Customers.Zona AS Zone, Q_Customers.NumeroTelefono AS Phone, Q_Customers.NumeroFax AS Fax, Q_Customers.Cell AS Mobile, Q_Customers.Email, Q_Customers.Codag AS SaleseosID, \"Q_Customers.Id anag\" AS Id_anag
FROM Q_Customers
ORDER BY Q_Customers.CodAnag";

[INDENT=2]Q_Customers.CodAnag AS CustomerID,
\"Q_Customers.Ragione sociale\" AS CompanyName,
Q_Customers.NomeContatto AS ContactName,
Q_Customers.Indirizzo AS Address,
LocalitÓ AS City,
Q_Customers.Provincia AS Region,
Q_Customers.CAP AS PostalCode,
Q_Customers.Nazione AS Country,
Q_Customers.Zona AS Zone,
Q_Customers.NumeroTelefono AS Phone,
Q_Customers.NumeroFax AS Fax,
Q_Customers.Cell AS Mobile,
Q_Customers.Email,
Q_Customers.Codag AS SaleseosID,
\"Q_Customers.Id anag\" AS Id_anag
[/INDENT]

FROM

[INDENT=2]Q_Customers
[/INDENT]

ORDER BY

[INDENT=2]Q_Customers.CodAnag
[/INDENT]";
sc_lookup(rs, $sql_customers, "conn_odbc");
// You have the array populated at this point (but you ought to check for errors of course)...
// Now we will write the other database...
$sql_insert_into ="

It says that --> Undefined variable: thevalues
I've tried to add $thevalues = ''; before sc_lookup but I don't know if it's correct

For sure ON DUPLICATE KEY UPDATE SET has big mistakes . I don't know how insert the data apart from the CustomerID that is the key.
The arrays sintax and use are not so easy to me... ;-(

Attached the image of error

Generally there are a couple of things that can cause problems, depending on your data.
I made a (possibly) bad assumption that the first query would in fact return some records.
To avoid errors when it does not, we need to add some code after the sc_lookup():

Code:

sc_lookup(rs, $sql_customers, "conn_odbc");
if ($rs === false) {

exit; // If we arrive here it means the SQL query was badly written

}
elseif (count($rs) == 0) {

exit; // If we arrive here it means that no records matched our query

}

In addition, between the two "foreach()" statements, add this line:

Code:

$thevalues = ""; // This ensures that the string is initialized, and cleared each time thru.