PHP连接到webmatrix中的mysql时出错


Getting a Error during PHP connection to mysql in webmatrix

我在尝试从webmatrix中的php文件连接到mysql数据库时出错,详细信息如下

这是PHP文件:

<!DOCTYPE html>
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$database = "image" ;
// Create connection
$conn = new mysqli($servername, $username, $password);
echo "Connected successfully";
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>
</body>
</html>

这是web.config文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <connectionStrings>
        <add connectionString="Server=localhost;Database=image;Uid=root;Pwd=password" name="image" providerName="MySql.Data.MySqlClient" />     
    </connectionStrings>
</configuration>

这是我得到的错误:

HTTP Error 403.14 - Forbidden
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
More Information:
This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.

我通过更改web.config文件添加默认文档来解决这个问题,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <connectionStrings>
        <add connectionString="Server=localhost;Database=image;Uid=root;Pwd=hrushikesh" name="image" providerName="MySql.Data.MySqlClient" />     
    </connectionStrings>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="sample.php" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>