2012-06-18 77 views
0

我的PHP代码:转义双引号

$query="select company_name from company_names where cik=".$cik; 

其中关于打印功能使

select company_name from company_names where cik=0001001871 

我想获得像

select company_name from company_names where cik='0001001871' 

输出如何添加PHP中的单引号?

+0

http://php.net/manual/en/language.types.string.php –

+0

但是,为什么你想在整数单引号 – 2012-06-18 06:51:52

+0

如果cik是字符串类型,那么你做一个愚蠢的东西存储int作为字符串 – 2012-06-18 06:52:41

回答

5

简单:

$query = "select company_name from company_names where cik = '$cik'"; 

或者:

$query = "select company_name from company_names where cik = '" . $cik . "'"; 

请注意,以防止SQL注入,看到这一点:

更多信息:

+0

如果$ cik包含麦当劳怎么办? – thebjorn

+1

@thebjorn:你需要自己提出这个问题,这回答了OP的问题,'cik = 0001001871'。它包含数字。 – Sarfraz

+0

谢谢你的答案... do yu知道postgres相当于mysql_fetch_assoc()? – user1371896

0
$query="select company_name from company_names where cik='".$cik."'";