mysql recommended connection and query data table PHP code

小云云
Release: 2023-03-20 14:08:01
Original
1323 people have browsed it

This article mainly shares with you the complete process of native mysql query, database selection, suggested connection and query data table PHP. I hope it can help everyone.

Use mysqli_connect, mysql_connect, mysqli_select_db, mysql_select_db
, mysqli_query, mysql_query to directly select the database, data table and query the complete code

database.php file is the user or password of the database, etc.

<?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
        ),
);?>
Copy after login
Copy after login
$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);
Copy after login

             

Use mysqli_connect, mysql_connect, mysqli_select_db, mysql_select_db
, mysqli_query, mysql_query to directly select the database. Data table and query the complete code

database.php file is the database User or password, etc.

<?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
        ),
);?>
Copy after login
Copy after login
$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);
相关推荐:
Copy after login
mysql查询表里的重复数据方法
Copy after login
<a href="http://www.php.cn/mysql-tutorials-358763.html" target="_self">详细介绍MySQL查询优化</a><br/>
Copy after login

The above is the detailed content of mysql recommended connection and query data table PHP code. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!