1
我有以下的PHP文件來創建數據庫和表:當它運行時我就返回此PHP錯誤創建MySQL表
<?php
$slName = $_POST['slName'];
$con=mysqli_connect('localhost', 'setlist', 'music');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create database
$sql="CREATE DATABASE $slName";
if (mysqli_query($con,$sql))
{
echo "Database " . $slName . " created successfully";
}
else
{
echo "Error creating database: " . mysqli_error();
}
// Create table
$tbl="CREATE TABLE main (name TEXT,orderno INT,Age TEXT)";
// Execute query
if (mysqli_query($con,$tbl))
{
echo "Table persons created successfully";
}
else
{
echo "Error creating table: " . mysqli_error();
}
?>
:
Database created successfully Error creating table:
我通過在命令提示符下執行該成功:
CREATE TABLE main (name TEXT,orderno INT,Age TEXT);
我在做什麼錯?
非常感謝!
羅蘭
您忘記選擇數據庫中創建表。 – 2013-03-05 12:30:35
我想你沒有選擇數據庫。它可能是問題 – 2013-03-05 12:31:29
http://www.php.net/manual/en/mysqli.select-db.php – 2013-03-05 12:32:15