Ram Sharma
Ram Sharma

Reputation: 8819

Single quote not inserting in oracle table/view from magento's custom code

I am trying to insert data in oracle table from magento's custom plugin/code. Below code is working for me but I am not able to insert single quote with values.

<?php
   $headerSql = "INSERT INTO MAGE_ORDER_INTF_HEADERS_DV (HEADER_REC_ID, IMPORT_SOURCE, IMPORT_SOURCE_INSTANCE)VALUES (".$header_rec_id.",'".$is."','".$isi."')";
   $q = $writeResourceOracle->prepare($headerSql);
   if($q->execute()) {
      echo 'success';
   }else{
      echo 'fail';
   }
?>

if I have plain data like john, shan, google it gets into db table but if the data is like mac's or anything which has single quote than oracle through error. Please help me out in this case.

Upvotes: 0

Views: 2579

Answers (2)

McLyn
McLyn

Reputation: 1

if you're using Oracle db, preferably 9i and up.. try:

INSERT TABLEHERE (COLUMNHERE) VALUES(q'|$value|');

Upvotes: 0

Deependra Singh
Deependra Singh

Reputation: 1514

in SQL text which has single quote can not be inserted directly, we have to use one extra quote before any single quote in a text. like mac's should be represented as mac''s. so lets prepare variables before putting them into SQL like this

//$value = "mac's";
$value = str_replace("'", "''", $value);

Upvotes: 4

Related Questions