php 如何在oracle查询中转义双引号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2044130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:47:04  来源:igfitidea点击:

How do I escape double quotes in oracle query?

phporacleescaping

提问by user61734

I have some text fields in the oracle table, which have double quotes. How to escape them in a select query, so that I can use it in PHP?

我在 oracle 表中有一些文本字段,它们有双引号。如何在选择查询中转义它们,以便我可以在 PHP 中使用它?

采纳答案by Peter Lang

You should be able to do a

你应该能够做一个

SELECT REPLACE(your_column, '"', '\"') AS your_escaped_column
FROM your_table;

回答by Adam Hawkes

Odds are, if you are trying to do this you are dealing with a SQL Injection vulnerability. Please Google this and think about what you're doing.

很可能,如果您尝试这样做,您正在处理 SQL 注入漏洞。请谷歌一下,想想你在做什么。

回答by Powerlord

Well... you'd select them out just like you would any other field. It's when you are putting things into the database where you need to escape them.

嗯...你会像选择任何其他领域一样选择它们。当您将东西放入数据库时,您需要对其进行转义。

That has different mechanisms depending on what database abstraction layer or driver you're using.

根据您使用的数据库抽象层或驱动程序,它具有不同的机制。

For drivers, I recommend PDO. That way, it doesn't matter which database you're using, escaping a field for input is always going to be something like this:

对于驱动程序,我推荐 PDO。这样,您使用哪个数据库并不重要,转义输入字段总是这样的:

// Assuming that $dbh is a valid PDO object, like this one:
// $dbh = new PDO('oci:dbname=//hostname:1521/scott', 'scott', 'tiger');
// That's 'oci:dbname=//hostname:port-number/database', username, password

$sql = "SELECT * FROM myTable WHERE name = ':myName'";
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':myName' => "Ed O'Neil"));

回答by zmbush

Have you tried: "\""

你有没有尝试过: ”\””