开发者

Create a table if it does not exist

I have written a code that should check weather there is a table called imei.$addimei and, if not, create it...

$userdatabase = mysqli_connect('localhost', 'root', 'marina', 'imei');
...
$result = mysqli_query($userdatabase, "SELECT * FROM imei".$addimei."" );
if ( !$result ) { echo('creating table...'); /// if no such table, make one!

mysql_query ( $userdatabase,
'CREATE TABLE imei'.$addimei.'(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),

EVENT varchar(15),
TIME varchar(25),
FL开发者_开发问答D1 varchar(35),
FLD2 varchar(35),
IP varchar(25),
)' );
}

Yet the CREATE TABLE somehow doesn't seem to work. Warning: mysql_query() expects parameter 1 to be string, object given in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 564

Any idea's what wrong? Thanks!


edit:

http://pt.php.net/manual/en/function.mysql-query.php

mysql_query (
'CREATE TABLE imei'.$addimei.'(
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,

EVENT varchar(15),
TIME varchar(25),
FLD1 varchar(35),
FLD2 varchar(35),
IP varchar(25))', $userdatabase );

EDIT: Hello, had to go yesterday, sorry... Your connection is mysqli, see EXAMPLE 2 in this page:

http://php.net/manual/en/mysqli.query.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜