0

Hi,

I am about to blow my brains out. Im sure you've been there!
I am trying to create a table in my MySQL database and getting this error -> SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ENGINE = MyISAM' at line 5

here is my code for it:

try {
				$userTable = 'u'.$userID;
				/*** set the error mode ***/
				$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$sql = "CREATE TABLE `".$userTable."` (
				`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
				`my_themes` INT NOT NULL, 
				`selected_theme` INT NOT NULL, 
				) ENGINE = MyISAM;";
				/*** our sql query ***/
				$done = $conn->prepare($sql);
				$done->execute();
			} catch(Exception $e) {
				echo '<h4>'.$e->getMessage().'</h4>';
			}

I have tried everything I could think of, however I am at a mind blank of what else to try.

Does anyone have any ideas on why this code wouldn't work?

Thanks for saving a life :) :)

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by QWaz
0

can you post the full page codes or you could try this

try {
				$userTable = 'u'.$userID;
				/*** set the error mode ***/
				$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$sql = "CREATE TABLE `".$userTable."` (
				`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
				`my_themes` INT NOT NULL, 
				`selected_theme` INT NOT NULL, 
				) ENGINE = MyISAM;";
				/*** our sql query ***/
				mysql_query($sql,$conn);
			} catch(Exception $e) {
				echo '<h4>'.$e->getMessage().'</h4>';
			}
0

can you post the full page codes or you could try this

Thanks for your suggestion, however I am using PHP PDO::MySQL, so I can't do it the way you suggested because then all my previous code wont' work.

The only issue I have is with this section. All the rest is working.

0

I have it solved myself.

I thought, Why not just go into phpMyAdmin and create a table the way i want it, and then use the 'create php code' thing to make it for me. that way how can I have an error, if it did it for me.

And bang. It worked.
Awesome.

Thanks for your help.

Cheers,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.