mysql 引用php中变量查询

来源:互联网 发布:淘宝联盟21号不能提现 编辑:程序博客网 时间:2024/06/16 12:16

1、没有变量的sql查询:

$sql=" select *  from ajaxtesttb where city='chengdu' and state='china' ";

2、有变量的sql查询:在字符串中用PHP变量的方法是变量外面用大括号

$sql=" select *  from ajaxtesttb where city='{$city}' and state='{$state}'";

$host="192.168.21.103";
$sql="select a.host_object_id,a.display_name host_name,a.address,c.display_name,b.state,b.start_time,b.end_time,b.output from nagios_hosts a,nagios_servicechecks b,nagios_services c where a.host_object_id=c.host_object_id and b.service_object_id=c.service_object_id and ( c.display_name='Current Load' or c.display_name='check-load') and a.address='{$host}' order by b.servicecheck_id desc limit 0,38";

整个sql语句要用""双引号括起来,然后php变量用单引号加大括号的形式:'{$host}'

0 0