簡體   English   中英

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM