Is there a problem with this code? Why can't I create database tables? & Lt ;? Php $ con & nbsp; = & nbsp; mysql_connect ("localhost", "root", "") & nbsp; or & nbsp; die ("connection error "); $ AB & nbsp; = & nbsp; mysql_select_db ("Is there a problem with the my_d code? Why can't I create database tables?
$ Con = mysql_connect ("localhost", "root", "") or die ("connection error ");
$ AB = mysql_select_db ("my_db", $ con );
If ($ AB ){
Echo "succeeded ";
}
$ SQL = "CREATE TABLE 'test '(
'Id' int (10) not null auto_increment,
'Uid' varchar (10) not null default '0 ',
'Regdate' date not null,
'Remark' text,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;
Insert into 'test' ('id', 'uid', 'regdate', 'remark') VALUES
(1, 'Zhang San', '2017-07-02 ', 'Student '),
(2, 'Li Si', '2017-07-03 ', 'studen '),
(3, 'Wang Wu', '2017-07-02 ', 'Worker '),
(4, 'Zhao Liu', '2017-07-01 ', 'studen ');
";
$ Abc = mysql_query ($ SQL, $ con );
If ($ abc ){
Echo "created successfully ";
} Else {
Echo "failed ";
}
?>
------ Solution --------------------
$ Con = mysql_connect ("localhost", "root", "") or die ("connection error ");
$ AB = mysql_select_db ("my_db", $ con );
If ($ AB ){
Echo "succeeded ";
}
$ SQL = "CREATE TABLE 'test '(
'Id' int (10) not null auto_increment,
'Uid' varchar (10) not null default '0 ',
'Regdate' date not null,
'Remark' text,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;
$ Abc = mysql_query ($ SQL, $ con );
If ($ abc ){
Echo "created successfully ";
} Else {
Echo "failed ";
}
$ Sql1 = "insert into 'test' ('id', 'uid', 'regdate', 'remark') VALUES
(1, 'Zhang San', '2017-07-02 ', 'Student ')"
$ Result = mysql_query ($ sql1 );
If ($ result ){
Echo "data inserted ";
}
------ Solution --------------------
Output the mysql error message of $ abc.
PS, 12 rows with fewer ending double quotation marks