数据库连接
百度BAE
......
public function responseMsg () {
$postStr = $GLOBALS ["HTTP_RAW_POST_DATA" ];
if (!empty ($postStr )){
$postObj = simplexml_load_string($postStr ,'SimpleXMLElement' ,LIBXML_NOCDATA);
$fromUsername = $postObj ->FromUserName;
$toUsername = $postObj ->ToUserName;
$type = $postObj ->MsgType;
$customrevent = $postObj ->Event;
$latitude = $postObj ->Location_X;
$longitude = $postObj ->Location_Y;
$keyword = trim($postObj ->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromeUserName><![CDATA[%s]]></FromeUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>"
$dbname = 'SnXAHxsmUPuRqZkaWnjF' ;
$host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP' );
$port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT' );
$user = getenv('HTTP_BAE_ENV_AK' );
$pwd = getenv('HTTP_BAE_ENV_SK' );
$link = @mysql_connect("{$host}:{$port}" ,$user ,$pwd ,true );
if (!$link ){
die ("Connect Server Failed: " .mysql_error());
}
if (!mysql_select_db($dbname ,$link )){
die ("Select Database Failed: " .mysql_error($link ));
}
$sql = "SELECT * FROM 'weixin' WHERE 'title' = '中国合伙人' LIMIT 0,30 " ;
$sql = "SELECT * FROM 'weixin' WHERE 'title' = '{$keyword}' LIMIT 0,30 " ;
$sql = "SELECT * FROM 'weixin' WHERE 'title' LIKE '%{$keyword}%' LIMIT 0,30 " ;
$query = mysql_query($sql );
$rs = mysql_fetch_array($query );
$contentStr = $rs ['content' ];
mysql_close($link );
$resultStr = sprintf($textTpl ,$fromUsername ,$toUsername ,$time ,$contentStr );
echo $resultStr ;
}else {
echo "" ;
exit ;
}
}
......