我一直在一个名为FreeHostia的免费托管网站上进行一些网站开发测试。我一直在尝试通过PHP创建数据库。然而,我的努力是徒劳的。查询失败,我没有错误代码。我的PHP代码如下所示:
<?php
// Create connection
$con=mysql_connect("localhost", "raslar10_players", "123456", "raslar10_players");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "Connected to MySQL";
}
// Create table
$sql = "CREATE TABLE Persons(FirstName CHAR(30),LastName CHAR(30),Age INT)";
if (mysqli_query($con, $sql)) {
echo "Table persons created successfully";
} else {
echo "Error creating table: " . mysqli_error($con);
}
?>
我做错了什么?该查询在phpMyAdmin中工作,并且连接正在运行。 (根据我的代码,反正)
答案 0 :(得分:11)
只需更改
$con=mysql_connect("localhost", "raslar10_players", "123456", "raslar10_players");
到
$con=mysqli_connect("localhost", "raslar10_players", "123456", "raslar10_players");