PHP連接資料庫並讀取資料列印

WBOY
發布: 2016-07-29 09:05:51
原創
2064 人瀏覽過

<code><span><span><?php</span><span>$link</span> = mysqli_connect(<span>"localhost"</span>,<span>"root"</span>,<span>"root"</span>) <span>or</span><span>die</span>(<span>"Connect error"</span>);
<span>if</span>(<span>$link</span>){
    <span>echo</span><span>"Connect success<br>"</span>;
    mysqli_select_db(<span>$link</span>, <span>"world"</span>);
    <span>$sql</span> = <span>"select * from city"</span>;
    <span>$result</span> = mysqli_query(<span>$link</span>, <span>$sql</span>);
    <span>$rows</span> = mysqli_num_rows(<span>$result</span>);
    <span>$cols</span> = mysqli_num_fields(<span>$result</span>);
    <span>echo</span><span>"rows are "</span>.<span>$rows</span>.<span>", cols are "</span>.<span>$cols</span>.<span>"<br>"</span>;
    <span>echo</span><span>"<table border='1' align='center' width='80%'>"</span>;
    <span>echo</span><span>"<caption>City info</caption>"</span>;
    <span>echo</span><span>"<th>ID</th><th>Name</th><th>CountryCode</th><th>District</th><th>Population</th>"</span>;
    <span>while</span> (<span>$row</span>=mysqli_fetch_row(<span>$result</span>)){
        <span>echo</span><span>"<tr align='center'>"</span>;
        <span>foreach</span> (<span>$row</span><span>as</span><span>$data</span>){
            <span>echo</span><span>"<td>"</span>.<span>$data</span>.<span>"</td>"</span>;
        }
        <span>echo</span><span>"</tr>"</span>;
    }
    <span>echo</span><span>"</table>"</span>;
}<span>else</span> {
    <span>echo</span><span>"Connect error"</span>;
}
<span>?></span></span></code>
登入後複製
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了PHP連接資料庫並讀取資料列印,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!