Create table if it doesn't exist
I wrote a code that should check the weather, there is a table named 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),
FLD1 varchar(35),
FLD2 varchar(35),
IP varchar(25),
)' );
}
However, CREATE TABLE somehow doesn't work. Warning: mysql_query () expects parameter 1 to be a string, the object is listed in C: \ xampp \ xampp \ htdocs \ mobi \ mainmenu.php on line 564
Any idea what's wrong? Thanks!
+2
a source to share
1 answer
change:
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: Hi happened yesterday, sorry ... Your connection is mysqli, see EXAMPLE 2 on this page:
+2
a source to share