Blogger Information
Blog 3
fans 0
comment 0
visits 2052
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP之MySQL三种连接方式
秦小凡的博客
Original
630 people have browsed it

<?php
//第一种方法
$db = mysqli_connect('127.0.0.1','root','root');
if(!$db){
   echo'失败了'.mysqli_connect_error;

}else{
   echo '<h1>成功了</h1>';
}
mysqli_select_db($db,'mysql');
mysqli_set_charset($db,'utf8');
echo'<br>';
//第一种方法
//第二种
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','root');
define('DB_UAME','mysql');
define('DB_CHAR','utf8');
$db = @mysqli_connect(DB_HOST,DB_USER,DB_PASS);
if(!$db){
   echo'失败了'.mysqli_connect_error($db);

}else{
   echo '<h1>成功了</h1>';
}
mysqli_select_db($db,DB_UAME);
mysqli_set_charset($db,DB_CHAR);
echo'<br>';
//第二种
//第三种
$db = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_UAME)
or die('失败了'.mysqli_connect_error);
mysqli_set_charset($db,DB_CHAR);

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!