gpt4 book ai didi

PHP - 创建表失败

转载 作者:行者123 更新时间:2023-12-01 00:22:11 25 4
gpt4 key购买 nike

因此,我试图在我的服务器上使用 PHP 创建一个表,但即使它正确连接到我的服务器,它也没有成功。这是我的代码:

// alphacrmTableCreate.php | Ryan Castle | 09/04/2014 - This script CREATEs sables     tCompany and tPerson in the database 'alphacrm'

{ // Connect and test mySQL and specific DB

$hostname = "localhost";
$username = "root";
$password = "";

$databaseName = "alphacrm";

$dbConnected = @mysql_connect($hostname, $username, $password);
$dbSelected = @mysql_select_db($databaseName, $dbConnected);

$dbSuccess = true;
if ($dbConnected) {
if (!$dbSelected) {
echo "DB connection FAILED<br><br>";
$dbSuccess = false;
} else {
echo "DB connection SUCCESSFUL<br><br>";
$dbSuccess = true;
}
} else
echo "mySQL connection FAILED<br><br>";
$dbSuccess = false;
}

if ($dbSuccess) {
//Table script here
echo "Table created";
} else {
echo "Table creation has failed";
}

我试图找出脚本中的错误,它看起来好像位于 if ($dbSuccess) { 行附近。如果我输入 if (!$dbSuccess) { 它会起作用,但这不会有帮助,因为它不能解决我的问题。任何帮助将不胜感激。~瑞安

最佳答案

您缺少 {

 else
echo "mySQL connection FAILED<br><br>";
$dbSuccess = false;
}

此外,您还必须关闭 if 语句。这是更正的完整 block

if ($dbConnected) {
if (!$dbSelected) {
echo "DB connection FAILED<br><br>";
$dbSuccess = false;
} else {
echo "DB connection SUCCESSFUL<br><br>";
$dbSuccess = true;
}
} else {
echo "mySQL connection FAILED<br><br>";
$dbSuccess = false;
}

}

关于PHP - 创建表失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com