如何在Oracle中插入PHP中的特殊字符


How to insert Special Characters from PHP in Oracle?

我想在oracle表中插入带有特殊字符的数据。我的代码是这样的-:

$query1 ="INSERT INTO sample(po_number , created_at , customer_firstname , customer_lastname , customer_email , 
shipping_description , ship_to_firstname, ship_to_lastname, ship_to_company, ship_to_street, ship_to_city, ship_to_country_id, ship_to_postcode, ship_to_telephone, increment_id) VALUES(".$result_str_order.")"; 

where $result_str_order = '100','21-Mar-2011','Sam','Right','sam.right@sasmple.com','Flight','Samy',
'RTR','SR INC','222,M.G.Bank's-Pipeline/Rd','Newyork','US','411230','999856230','20000507'

现在,如果是ship_to_street,我需要插入222,M.G.银行的管道/Rd但是它包含特殊字符,如',-,/etc。so如何在oracledb中插入特殊字符

唯一需要转义的字符是'(因为您使用单引号作为字符串分隔符)。那就是:

$query1 ="INSERT INTO sample(po_number , created_at , customer_firstname , customer_lastname , customer_email , 
shipping_description , ship_to_firstname, ship_to_lastname, ship_to_company, ship_to_street, ship_to_city, ship_to_country_id, ship_to_postcode, ship_to_telephone, increment_id) VALUES(".$result_str_order.")"; 

where $result_str_order = '100','21-Mar-2011','Sam','Right','sam.right@sasmple.com','Flight','Samy',
'RTR','SR INC','222,M.G.Bank''s-Pipeline/Rd','Newyork','US','411230','999856230','20000507'

使用Replace方法(针对变量,而不是整个查询)来重复单引号。

我也有同样的问题。我想选择这个■××特殊字符作为条件。

  SELECT * 
  FROM tablename
  WHERE table = '■××'

我使用了带有oracle dB的PHP MMSQL。为了解决这个问题,我使用了十六进制转换RAWTOHEX

SELECT * 
FROM tablename
WHERE RAWTOHEX(table) = '81A1817E817E' --this is the hex for symbol above

您可以使用带引号的字符串,如q'[$visitComment]',其中$visitComment是一个包含特殊字符串的变量。

或者可以外部绑定INSERT INTO样本(列)值(:columnval);oci_bind_by_name($result,':columnval',$string);

其中$result是$result=oci_parse($conn,$query);

注意:-这只适用于包含字符串的变量。