你好我是新来的,
但是我用sqlsrv创建了2个不同的鳕鱼,它连接到sql server 2012
但是当我用mysqli创建另一个php代码时,它返回错误,任何想法为什么?
sqlsrv的第一个代码:
$connect = array( "UID" => "admin", "PWD" => "admin2017", "Database" => "sunto" );
$link = sqlsrv_connect( "localhost", $connect );
if( $link ) {
echo "Connection established.<br />";
} else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true ) );
}
使用mysqli_connect的另一个代码:
<?php
$hostname = "localhost";
$username = "admin";
$password = "admin2017";
$databaseName = "sunto";
$dbConnected = mysqli_connect($hostname, $username, $password);
$dbSelected = mysqli_select_db($dbConnected, $databaseName);
?>
显示以下错误!!
警告:mysqli_connect():( HY000 / 2002):无法建立连接 因为目标机器主动拒绝它。在 第10行的C:\ Apache24 \ htdocs \ index3.php
警告:mysqli_select_db()期望参数1为mysqli,boolean 在第12行的C:\ Apache24 \ htdocs \ index3.php中给出
答案 0 :(得分:-1)
在php.ini(xampp-&gt; php-&gt; php.ini)配置文件中查找mysqli。 你可以在那个文件中找到; extension = php_mysqli.dll 。取消注释(extension = php_mysqli.dll)这个并尝试下面的代码。
<?php
@session_start();
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>