Okay, also versuche ich meine PHP-Programm/PHP-Dateien in eine .exe-Ausgabe zu konvertieren, so dass es von jedem ausgeführt werden kann ich die Datei an, wo auch immer sie sind. Es funktioniert perfekt an meinem Ende. Wenn mein Freund jedoch die gleiche EXE-Datei auf seinem eigenen Computer ausführt, gibt es einen Fehler, der besagt, dass er keine Verbindung zu meiner Datenbank herstellen kann. Ich möchte, dass er auf das Programm zugreift, ohne zusätzliche Software und sonstiges herunterladen zu müssen. Ich versuchte, einige mögliche Lösungen zu lesen, und ich fand etwas, das vorschlägt, dass ich das in meinen Datenbankverbindungscode einschließen sollte. Sie verwendeten auch Server2Go, damit es funktioniert:PHP Exe Ausgabe - kann nicht auf Datenbank zugreifen
<?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.");
?>
Die Sache ist, ich bin nicht sicher, wie man richtig ich zur Zeit an den Verbindungscode zu integrieren haben. Der Fehler bezieht sich immer auf $ conn = mysqli_connect .... portion. Hier ist mein bestehender Verbindungscode. Wie integriere ich die vorgeschlagene Lösung?
<?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 "";
}
?>
wenn Sie ausführbare Dateien wollen, PHP ist die schlechteste Sprache in schreiben –
Sie sollten PHP mit sqlite anstelle von mysql im Falle von .exe verbinden (Desktop app) –