Home >Backend Development >PHP Tutorial >51 PHP page staticization 4

51 PHP page staticization 4

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:13:081023browse

All pure static - partial pure static
51 PHP 页面静态化4

51 PHP 页面静态化4


implementation steps:
51 PHP 页面静态化4


1. Write interface

<code><span><span><?php</span><span>//排行榜接口数据</span><span>//1. 获取数据</span><span>//2. 把我们获取到的数据组装成接口数据提供通信</span><span>//<strong>连接数据库</strong></span><span><strong>require</strong>_once</span>(<span>'./db.php'</span>);

<span>$connect</span> = Db::getInstance()->connect();

<span>$sql</span> = <span>'select * from hit as a join news as b on a.news_id=b.id order by a.count desc limit 3'</span>;

<span>$result</span> = mysql_query(<span>$sql</span>,<span>$connect</span>);

<span>while</span>(<span>$row</span> = mysql_fetch_assoc(<span>$result</span>))
{
    <span>$res</span>[] = <span>$row</span>;
}

<span>// 1 代表成功代码</span><span>return</span> show(<span>1</span>,<span>'success'</span>,<span>$res</span>);

<span>//将数据生成接口数据</span><span><span>function</span><span>show</span><span>(<span>$code</span>=<span>0</span>,<span>$message</span>=<span>'error'</span>,<span>$data</span>=array<span>()</span>)</span>
{</span><span>$result</span> = <span>array</span>(
        <span>'code'</span>=><span>$code</span>,
        <span>'message'</span>=><span>$message</span>,
        <span>'data'</span>=><span>$data</span>,
    );
    <span>echo</span> json_encode(<span>$result</span>);
}</span></span></code>
<code>插件名称:<span>JSON</span>-handle</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced 51 PHP page staticization 4, including require and database connection. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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
Previous article:CookieNext article:Cookie