首頁 >後端開發 >php教程 >mysql建議連接及查詢資料表PHP程式碼

mysql建議連接及查詢資料表PHP程式碼

小云云
小云云原創
2018-02-27 11:02:351440瀏覽

本文主要和大家分享原生mysql查詢,選擇資料庫,建議連線及查詢資料表PHP完整流程,希望能幫助大家。

用mysqli_connect,mysql_connect,mysqli_select_db,mysql_select_db
,mysqli_query,mysql_query直接選擇資料庫.資料表並進行查詢完整程式碼

##database.php檔案為資料庫的使用者或密碼等

<?phpreturn array (    &#39;default&#39; => array (        &#39;hostname&#39; => &#39;127.0.0.1&#39;,        &#39;database&#39; => &#39;phpcms&#39;,        &#39;username&#39; => &#39;root&#39;,        &#39;password&#39; => &#39;root&#39;,        &#39;tablepre&#39; => &#39;v9_&#39;,        &#39;charset&#39; => &#39;utf8&#39;,        &#39;type&#39; => &#39;mysql&#39;,        &#39;debug&#39; => true,        &#39;pconnect&#39; => 0,        &#39;autoconnect&#39; => 0
        ),
);?>
$mysql_user=include(PHPS_PATH.&#39;/caches/configs/database.php&#39;);//得到数据库配置        $username=$mysql_user[&#39;default&#39;][&#39;username&#39;];        $password=$mysql_user[&#39;default&#39;][&#39;password&#39;];        $tablepre=$mysql_user[&#39;default&#39;][&#39;tablepre&#39;];        $database=$mysql_user[&#39;default&#39;][&#39;database&#39;];        $con = mysqli_connect($mysql_user[&#39;default&#39;][&#39;hostname&#39;],$username,$password);//句柄

mysqli_select_db($con,$database);//选择数据库 
$sql = &#39; SELECT * FROM &#39;.$tablepre."pay_account where trade_sn=&#39;".$out_trade_no."&#39;";//file_put_contents(&#39;3.txt&#39;,$sql);$result2=mysqli_query($con,$sql);$orderinfo=mysqli_fetch_array($result2);;$uid=$orderinfo[&#39;userid&#39;];//更新数据库$sql4 = &#39; update  &#39;.$tablepre."pay_account set status= &#39;succ&#39;  where userid=".$uid ." and trade_sn=&#39;".$out_trade_no."&#39;";        $result4=mysqli_query($con,$sql4);
                 mysqli_close($con);

               

使用mysqli_connect,mysql_connect,mysqli_select_db,mysql_select_db

,mysql#query,mysqli_select_db,mysql_select_db
,mysql#query,mysqli_select_db,mysql_select_db

,mysql#query,mysqli_select_db,mysql_select_db

,mysql#query,mysqli_select.的用戶或密碼等

<?phpreturn array (    &#39;default&#39; => array (        &#39;hostname&#39; => &#39;127.0.0.1&#39;,        &#39;database&#39; => &#39;phpcms&#39;,        &#39;username&#39; => &#39;root&#39;,        &#39;password&#39; => &#39;root&#39;,        &#39;tablepre&#39; => &#39;v9_&#39;,        &#39;charset&#39; => &#39;utf8&#39;,        &#39;type&#39; => &#39;mysql&#39;,        &#39;debug&#39; => true,        &#39;pconnect&#39; => 0,        &#39;autoconnect&#39; => 0
        ),
);?>
$mysql_user=include(PHPS_PATH.&#39;/caches/configs/database.php&#39;);//得到数据库配置        $username=$mysql_user[&#39;default&#39;][&#39;username&#39;];        $password=$mysql_user[&#39;default&#39;][&#39;password&#39;];        $tablepre=$mysql_user[&#39;default&#39;][&#39;tablepre&#39;];        $database=$mysql_user[&#39;default&#39;][&#39;database&#39;];        $con = mysqli_connect($mysql_user[&#39;default&#39;][&#39;hostname&#39;],$username,$password);//句柄

mysqli_select_db($con,$database);//选择数据库 
$sql = &#39; SELECT * FROM &#39;.$tablepre."pay_account where trade_sn=&#39;".$out_trade_no."&#39;";//file_put_contents(&#39;3.txt&#39;,$sql);$result2=mysqli_query($con,$sql);$orderinfo=mysqli_fetch_array($result2);;$uid=$orderinfo[&#39;userid&#39;];//更新数据库$sql4 = &#39; update  &#39;.$tablepre."pay_account set status= &#39;succ&#39;  where userid=".$uid ." and trade_sn=&#39;".$out_trade_no."&#39;";        $result4=mysqli_query($con,$sql4);
                 mysqli_close($con);
相关推荐:
mysql查询表里的重复数据方法
<a href="http://www.php.cn/mysql-tutorials-358763.html" target="_self">详细介绍MySQL查询优化</a><br/>

以上是mysql建議連接及查詢資料表PHP程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn