Reading from oracle, writing to sql - quotation problem

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

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 ''.


$oracleQuery = ....
$stid = oci_parse($conn, $oracleQuery);
$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){
$valuesToInsert = $valuesToInsert. '\'' .$item. '\'';

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

}//end if

}//end for

$valuesToInsert = $valuesToInsert. ')';

$insertSQLQuery = "INSERT INTO [DLA_Requests]


PLEASE ADVISE :) I am a beginner!


Post Reply