从mysql转换时mysqli错误

时间:2017-05-04 03:06:22

标签: php mysql mysqli

我正在尝试将我的MySQL代码转换为MYSQLI,但它在第21行出错。我无法识别我必须纠正第21行错误。有人可以帮帮我吗?

$conn = mysqli_connect($host,$username,$password) or die(mysqli_error());
mysqli_select_db($conn,$dbname) or die(mysqli_error());
mysqli_set_charset($conn , "utf8");






 mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `cookies` (
`ip` varchar(32) NOT NULL DEFAULT '',
`time` varchar(32) DEFAULT NULL,
`waktu` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ip`)
ENGINE=MyISAM DEFAULT CHARSET=utf8;
) 
");

1 个答案:

答案 0 :(得分:0)

您的mysqli_error应该有一个参数。 mysqli_error($connection)

此处编辑的代码:

$conn = mysqli_connect($host,$username,$password);
mysqli_select_db($conn,$dbname) or die(mysqli_error($conn));
mysqli_set_charset($conn , "utf8");

mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `cookies` (
        `ip` varchar(32) NOT NULL DEFAULT '',
        `time` varchar(32) DEFAULT NULL,
        `waktu` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`ip`)
        ENGINE=MyISAM DEFAULT CHARSET=utf8;
        ) 
");