简体   繁体   中英

mysql 1064 error SYNTAX ERROR

I keep getting this error every time i try to create a table in my sql database:

Error in query (1064): Syntax error near 'CREATE TABLE IF NOT EXISTS users ( id int(10) NOT NULL AUTO_INCREMENT, `' at line 2

Could I get some help with this?

use luke_f_db
CREATE TABLE IF NOT EXISTS `users` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `username` varchar(50) NOT NULL,
 `email` varchar(50) NOT NULL,
 `password` varchar(50) NOT NULL,
 `trn_date` datetime NOT NULL,
 PRIMARY KEY (`id`)
 );

There's an error with your use command. Add an ; behind the first line or just check if the database exists and your account has access to it.

The CREATE Code worked fine for me.

You could run only one command per query**. The mySQL command line client allows you to split multiple commands with ; but still runs them sequentially.

Remove the use luke_f_db line. The database to be used should be selected within the connect command. See http://www.w3schools.com/php/func_mysqli_connect.asp :

$con = mysqli_connect("localhost","my_user","my_password","my_db");

The database name is the last argument to mysqli_connect.

The same information is found in the official PHP documentation: http://php.net/manual/en/mysqli.construct.php

** Some mySQL client implementations also allow multiple commands in one call, but you should avoid it. Using this feature in a script isn't portable to other databases and you won't ever know which of your commands triggered an error if one occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM