好吧,所以我試圖將我的php程序/ php文件轉換爲.exe輸出,以便它可以由任何我給予文件的人運行,無論他們在哪裏。它完全符合我的要求。但是,當我的朋友在他自己的計算機上運行相同的.exe文件時,有一個錯誤說明它無法連接到我的數據庫。我希望他能夠訪問該程序,而無需下載其他軟件和內容。我嘗試閱讀一些可能的解決方案,並發現一些建議我應該將其包含在我的數據庫連接代碼中的內容。他們還使用Server2go,使其工作:PHP Exe輸出 - 無法訪問數據庫
<?php
// ExeOutput for PHP: MySQL sample using the WAMP package Server2Go
// By default, Server2go comes with a sample database. Root admin is not password-protected.
$mysqlusername = "root";
$mysqlpass = "";
// Do not modify the following lines
$mysqlport = getenv('S2G_MYSQL_PORT');
$mysqlhost = "localhost:".$mysqlport;
// We verify that our ExeOutput application was started by Server2go, otherwise, the MySQL server may not have started.
if (empty($mysqlport)) die("This application cannot be started directly. Programmers: please use the Server2go EXE file, it will start this application automatically.");
?>
的事情是我不知道如何正確地將其集成到連接代碼我現在有。錯誤總是指$ conn = mysqli_connect ....部分。這是我現有的連接代碼。我如何整合建議的解決方案?
<?php
function db_connect()
{
$host = "localhost";
$user = "root";
$password = "";
$database = "csv_db";
$conn = mysqli_connect($host, $user, $password, $database);
if ($conn == FALSE)
{
echo "Error: Unable to connect to the database!";
return NULL;
}
return $conn;
}
function db_disconnect($conn)
{
mysqli_close($conn);
return;
}
function checkUserAccessCookie()
{
/* Check if the user has the "userAccess" cookie (set during login) */
if (isset($_COOKIE["userAccess"]))
{
return true;
}
return false;
}
function getDefaultUserFromCookie()
{
/* If the user has been here before, then a cookie named "userLogin"
* with the user's username will be available. */
if (isset($_COOKIE["userLogin"]))
{
return $_COOKIE["userLogin"];
}
/* If the cookie does not exist, then return blank instead */
return "";
}
?>
如果你想可執行文件,PHP是寫在最壞的語言 –
你應該使用sqlite而不是mysql連接php以防.exe(桌面應用程序) –