[英]How to make a sql query with variables work from php?
从命令行(sqlcmd)运行时,此查询有效。 我不知道如何使其在php脚本中工作。
exec sp_executesql N'select N2."Name" from (("dbo"."BasicAnimal" N0 left join "dbo"."AnimalGroup" N1 on (N0."Group" = N1."OID")) left join "dbo"."AbstractGroup" N2 on (N1."OID" = N2."OID"))where (N0."GCRecord" is null and (((N0."IsCulled" = @p0) and N0."ExitDate" is null) or (not (N0."Group" is null) and N0."ExitDate" is null)))',N'@p0 nvarchar(8)',@p0=N'False'
go
如果我将上述查询从php脚本中换成类似以下基本内容:
select * from dbo.AnimalGroup
有用...
问题是查询本身包含单引号和双引号,因此我无法创建php变量,例如:
$sql='query goes here'
要么
$sql="query goes here"
你可以这样做:
$sql = 'single "dobuble" \' again single quotes\' '
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.