如何在Oracle中插入PHP中的特殊字符?
I want to insert data with special character in oracle tables. My code is like this-:
$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'
Now, in case of ship_to_street, I need to insert 222,M.G.Bank's-Pipeline/Rd but it contains special character like ,',-,/ etc.so how to insert special characters in oracle db?
我想在oracle表中插入具有特殊字符的数据。 我的代码是这样的 - : p>
$ 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。”)“;
其中$ result_str_order ='100','21-Mar-2011','Sam','Right','sam.right @sasmple.com','Flight','Samy',
' RTR','SR INC','222,MGBank's-Pipeline / Rd','Newyork','US','411230','999856230','20000507'
code> pre>
现在,如果是ship_to_street,我需要插入 222,MGBank's-Pipeline / Rd strong>
但它包含特殊字符,如', - ,/ etcso 如何在oracle db中插入特殊字符? strong> p>
div>
The only character you need to escape is '
(because you're using single quotes as string delimiters). So that's:
$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'
Use a Replace method (on your variables, not the entire query) to duplicate single quotes.
You can use quoted string like q'[$visitComment]' where $visitComment is a variable that contains a special character string.
Or you can bind externally INSERT INTO sample(column) values (:columnval); oci_bind_by_name($result, ':columnval',$string);
Where $result is $result = oci_parse($conn, $query);
Note:- This will work only for variable containing string.