PHP从MySQL数据库读出数据用在微信大众号上

WBOY
Release: 2016-06-13 12:22:17
Original
1019 people have browsed it

PHP从MySQL数据库读出数据用在微信公众号上

本帖最后由 u014294325 于 2015-06-19 09:51:33 编辑 做微信公众平台 在php页面从数据库中读取数据,用在微信公众平台的关注自动回复上
求指教怎么做
<br />public function handleEvent($postObj)<br />	{<br />		<br />		 //header('Content-type:text/html;charset=utf-8');                                 //定义输出格式编码为utf-8<br />   $db = new mysqli('127.0.0.1','root','123','weixin');                               //建立mysql数据库连接<br />   $_ROWS = $db->query('SELECT * FROM event_subscribe');                          //用sql语句获取数据<br />   //mysql_query("set names utf8");//设置编码utf8<br />   while($_ROW = $_ROWS->fetch_assoc())<br />        //$title= $_ROW->ess_Title;<br />    	//$Description= $_ROW->ess_Description;<br />    	//$PicUrl= $_ROW->ess_PictureUrl;<br />    	//$Url= $row->ess_Url;  <br /><br />        $title= $_ROW['ess_Title'];<br />    	$Description= $_ROW['ess_Description'];<br />    	$PicUrl= $_ROW['ess_PictureUrl'];<br />    	$Url= $row['ess_Url'];  <br />		//$contentStr = "欢迎关注哟";  <br />		$fromUsername = $postObj->FromUserName;<br />		$toUsername = $postObj->ToUserName;<br />		$msgType = "news";  <br />		$time = time();<br />		$textTpl = "<xml><br /> 					<ToUserName><![CDATA[%s]]></ToUserName><br /> 					<FromUserName><![CDATA[%s]]></FromUserName><br /> 					<CreateTime>%s</CreateTime><br />					<MsgType><![CDATA[news]]></MsgType><br /> 					<ArticleCount>1</ArticleCount><br /> 					<Articles><br /> 						<item><br /> 							<Title><![CDATA[%s]]></Title> <br /> 							<Description><![CDATA[%s]]></Description><br /> 							<PicUrl><![CDATA[%s]]></PicUrl><br /> 							<Url><![CDATA[%s]]></Url><br /> 						</item> 						<br /> 					</Articles><br /> 					<FuncFlag>1</FuncFlag><br /> 				</xml>";<br />		<br />		$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$title,$Description,$PicUrl,$Url);<br />        echo $resultStr;    
Copy after login

------解决思路----------------------
新的代码
<br />public function handleEvent($postObj)<br />    {<br />          <br />   //header('Content-type:text/html;charset=utf-8');                                 //定义输出格式编码为utf-8<br />   $db = new mysqli('127.0.0.1','root','123','weixin');                               //建立mysql数据库连接<br />   $db->query("SET NAMES utf8");//防止乱码<br />   $_ROWS = $db->query('SELECT * FROM event_subscribe where IsPublic=1');                          //用sql语句获取数据<br />   $_ROW = mysqli_fetch_assoc($_ROWS);<br />      $textTpl = "<xml><br />                     <ToUserName><![CDATA[%s]]></ToUserName><br />                     <FromUserName><![CDATA[%s]]></FromUserName><br />                     <CreateTime>%s</CreateTime><br />                    <MsgType><![CDATA[news]]></MsgType><br />                     <ArticleCount>1</ArticleCount><br />                     <Articles><br />                         <item><br />                             <Title><![CDATA[%s]]></Title> <br />                             <Description><![CDATA[%s]]></Description><br />                             <PicUrl><![CDATA[%s]]></PicUrl><br />                             <Url><![CDATA[%s]]></Url><br />                         </item>                        <br />                     </Articles><br />                     <FuncFlag>1</FuncFlag><br />                 </xml>";<br />         <br />        $resultStr = sprintf($textTpl, $postObj->FromUserName, $postObj->ToUserName, time(),$_ROW['ess_Title'],$_ROW['ess_Description'],$_ROW['ess_PictureUrl'],$_ROW['ess_Url']);<br />        <br />        return $resultStr;<br />    }  <br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template