PDO 链接数据库方式

Published
July 7, 2022
浏览次数 :  0

//PDO链接数据方式
$sName = '';

$uName = '';

$pass = '';

$dbName = '';

//create database connection
try {
  $conn = new PDO("mysql:host=$sName;dbname=$dbName",$uName,$pass);
  $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  
}catch(PDOException $e) {
  echo "Connection Failed: " . $e->getMessage();

}

//mysql 链接数据方式
$HOSTNAME = '';
$HOSTADMIN = '';
$HOSTPASSWORD = '';
$HOSTBASE = '';
$conn = new mysqli($HOSTNAME,$HOSTADMIN,$HOSTPASSWORD,$HOSTBASE);
$login = 0;
$inValid = 0;
if (!$conn) {
  die(mysqli_error($conn));
} 

Top