Use PHP to link to mysqli, after successful use, Mysqli_query () Create DATABASE and data table.
<php
$con = Mysqli_connect ("localhost", "root", "root");
if (! $con)
{
Die ("No connection succeeded". Mysqli_error ());
};
if (!mysqli_query ($con, "CREATE Database Jiangxia"))
{
Die ("No success created". Mysqli_error ());
}
mysqli_select_db ($con, "Jiangxia");
$sql = "CREATE TABLE Huangyan
(UserName Vachar (15),
Usersex Vachar (15)
)";
Mysqli_query ($con, $sql);
Mysqli_colse ($con);
?>
1,** It is important to note that if a database has been established, the code:
********
if (!mysqli_query ($con, "CREATE Database Jiangxia"))
{
Die ("No success created". Mysqli_error ());
}
*******
, which can cause subsequent statements to be unable to execute.
The workaround is to use the while instead of if:
$i = 1;
while ((!mysqli_query ($con, "CREATE Database Jiangxia")) &i)
{
Echo ("wrong");
$i = $i-1;
};
The code to be solved is a bit verbose. Perhaps we have no need to judge this at all.
The parameter positions of the 2,mysql_* and mysqli_* are reversed. This needs attention.
3,mysql_query () is itself a command, whether it is a single line or a judgment condition for a function such as if.
PHP create MySQL database and data table