我试图在数据库中创建表。数据库test
存在,我得到错误No database selected
。我相信,我使用的代码$select_db = mysql_select_db($database);
错误:未在php中选择数据库
这里是代码选择的数据库:
$host_name = 'localhost';
$user_name = 'root';
$password = '';
$database = "test";
$connection = mysqli_connect($host_name,$user_name,$password);
$select_db = mysql_select_db($database);
if ($select_db) {
echo "Database found <br>";
# code...
}
else
{
echo "Database not found <br>";
}
//code Working correctly till DATABASE FOUND.
$sql = "CREATE TABLE employee (employee_id INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT , Name CHAR(30) NOT NULL)";
if (mysqli_query($connection,$sql))
{
# code...
echo "Table created successfully";
}
else
{
echo "Table not created with the following error<br><strong>".mysqli_error($connection)."</strong>";
}
/*$db_close = mysql_close($Connection);
if ($db_close) {
echo "Connection closed";
# code...
}
else
{
echo "Connection not closed";
}*/
?>