Reading from oracle, writing to sql - quotation problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

adke001458
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Aug 11, 2014 12:50 am

Reading from oracle, writing to sql - quotation problem

Postby adke001458 » Thu Aug 14, 2014 12:20 am

Hi all,

I am currently using php to read data from on oracle db, and then write it to a sql db.

I have a slight problem. Some of the data in the oracle db contains quotation marks. for example

Intn'l - this is one of the values for example. My insert into statement fails as soon as it hits a value with quotation marks as it tries to close the query. How do I stop this?

I am aware that using '' stops the error, but as I don't know what the values in the oracle db are going to be, I need some kind of if statement when reading the data that says if value contains ' change to ''.

Code:

$oracleQuery = ....
$stid = oci_parse($conn, $oracleQuery);
oci_execute($stid);
$nfields = oci_num_fields($stid);

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)){

$whileNumber = $whileNumber + 1;
$valuesToInsert = "(";

$i = 0;

foreach ($row as $item){
$i++;
$valuesToInsert = $valuesToInsert. '\'' .$item. '\'';

if ($i < $nfields) {
$valuesToInsert = $valuesToInsert. ',';

}//end if


}//end for

$valuesToInsert = $valuesToInsert. ')';

$insertSQLQuery = "INSERT INTO [DLA_Requests]
values"
.$valuesToInsert;

$conn2->execute($insertSQLQuery);


PLEASE ADVISE :) I am a beginner!

Thanks
Adam

Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron