实例代码:
db=mysqlconnect(“qvnxelmkchho.rds.sae.sina.com.cn”.′:′.′10338′,′root′,′admin888′);mysqlselectdb(‘demo′);mysqlquery(‘SETNAMESUTF8′);sql=”SELECT title,description,picUrl,url FROM img ORDER BY ids LIMIT 0,10”;
res=mysqlquery(sql)
//循环取出数据
itemCount=0;//统计有几条数据while(row=mysql_fetch_assoc($res)){
$contentStr.= sprintf($newsTplItem,$row['title'],$row['description'],$row['picUrl'],$row['url']);
++$itemCount;//统计有几条数据
}
$newsTplHeader=sprintf($newsTplHeader,$fromUsername,$toUsername,$time,$itemCount);
$resultStr=$newsTplHeader.$contentStr.$newsTplFooter;
echo $resultStr;
核心代码:分离模板
$newsTplHeader=”
本文通过实例展示了如何使用PHP连接MySQL数据库并执行查询操作,包括设置字符集、构造SQL语句、执行查询及处理结果等关键步骤。
2229

被折叠的 条评论
为什么被折叠?



