当前位置:Gxlcms > PHP教程 > mysql建议连接及查询数据表PHP代码

mysql建议连接及查询数据表PHP代码

时间:2021-07-01 10:21:17 帮助过:16人阅读

本文主要和大家分享原生mysql查询,选择数据库,建议连接及查询数据表PHP完整流程,希望能帮助到大家。

用mysqli_connect,mysql_connect,mysqli_select_db,mysql_select_db
,mysqli_query,mysql_query直接选择数据库.数据表并进行查询完整代码

database.php文件为数据库的用户或密码等

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

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

用mysqli_connect,mysql_connect,mysqli_select_db,mysql_select_db
,mysqli_query,mysql_query直接选择数据库.数据表并进行查询完整代码

database.php文件为数据库的用户或密码等

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

mysqli_select_db($con,$database);//选择数据库 
$sql = ' SELECT * FROM '.$tablepre."pay_account where trade_sn='".$out_trade_no."'";//file_put_contents('3.txt',$sql);$result2=mysqli_query($con,$sql);$orderinfo=mysqli_fetch_array($result2);;$uid=$orderinfo['userid'];//更新数据库$sql4 = ' update  '.$tablepre."pay_account set status= 'succ'  where userid=".$uid ." and trade_sn='".$out_trade_no."'";        $result4=mysqli_query($con,$sql4);
                 mysqli_close($con);
相关推荐:
mysql查询表里的重复数据方法
详细介绍MySQL查询优化

以上就是mysql建议连接及查询数据表PHP代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行