sql comment error - php

i export this sql from a drupal site through phpmyadmin
CREATE TABLE `admin_language` (
`uid` int(10) UNSIGNED NOT NULL DEFAULT '0'COMMENT AS `Primary Key: Unique user ID.`,
`language` varchar(12) NOT NULL DEFAULT ''COMMENT AS `User’s default administration language.`
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores user admin language selections.';
but when i import to another mysql through phpmyadmin, there is an error
#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 'AS
`Primary Key: Unique user ID.`, `language` varchar(12) NOT NULL DEFAULT ''' at
line 2
anyone know what is the problem?

Change the quotes of the comments. From `` to ''

Related

How do i fix this problem ive tried alot?

I run into an SQL query error.
The query:
CREATE TABLE IF NOT EXISTS `shoutbox` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`user` varchar(255) NOT NULL,
`msg` varchar(255) NOT NULL,
`time` datetime(6) DEFAULT NOT NULL CURRENT_TIMESTAMP(6),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
MySQL said:
#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
'(6) DEFAULT NOT NULL CURRENT_TIMESTAMP(6),
PRIMARY KEY (`id`)
) ENGINE=MyISAM ' at line 5
Since this looks like your first import.
MySQL reference manuals are per the link. As you can see 5.5 is so old its in a PDF version only.
Since you are importing a sql file, look closer at the text of it, it will say what version it came from. The first step should be to install the same major version of mysql (the first two digits like 5.7 or 8.0). If the last digit is later than the origin sql that's fine.
Don't start with 5.5, its too old. Consider a minimum of 5.7 first or 8.0 if the version of the sql dump is later.
Default keyword should be before the default value
`time` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
assuming the posted code has been transcribed accurately this amendment fixes the posted error...
AND what's the point of not null AND a default?

How to fix SQL error with dropping a table in PHP?

I have created a web you can upload and download files - everything works perfect. But now, I want to create a init file, that delete old records in database and create a new tables in it.
So I write this:
$command = "
IF OBJECT_ID(`".$database.".Users`) IS NOT NULL
DROP TABLE ".$database.".Users;
IF OBJECT_ID(`".$database.".Uploads`) IS NOT NULL
DROP TABLE ".$database.".Uploads;
CREATE TABLE `Users` (
`Id` int(11) NOT NULL,
`User` text NOT NULL,
`Password` text NOT NULL,
`Permission` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
ALTER TABLE `Users` ADD PRIMARY KEY (`Id`);
ALTER TABLE `Users` MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=0;
CREATE TABLE `Uploads` (
`Id` int(11) NOT NULL,
`Name` text NOT NULL,
`User` text NOT NULL,
`Comment` text NOT NULL,
`Path` text NOT NULL,
`Permission` int(11) NOT NULL,
`Date` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
ALTER TABLE `Uploads` ADD PRIMARY KEY (`Id`);
ALTER TABLE `Uploads` MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=0;
";
$result = mysqli_query($conn, $command) or die(mysqli_error($conn));
I think, that code is right (but obviously not). When I run it, SQL throws an error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF OBJECT_ID(db.Users) IS NOT NULL DROP TABLE db.User' at line 1**.
This means that it don’t have a problem with connection to SQL database.
I tried instead of IF OBJECT_ID use IF NOT EXISTS, but it doesn't works too. Can anybody tell me if multi-line SQL command is this problem or if it is something else?
Note: I use 5.5.37 version of MariaDB (if it helps)
IF is not a valid SQL statement in MySQL / MariaDB.
The IF OBJECT_ID(...) statement in the question appears to be a Transact-SQL (Microsoft SQL Server) construct.
The equivalent functionality in MySQL would be achieved with
DROP TABLE IF EXISTS foo.mytable ;
(I expect this would work in MariaDB 5.5, but I haven't verified.)
Note that if the table doesn't exist, the execution of the statement will raise a warning. (A warning message, not an error message.)
The mysqli_query function runs a single statement. To run multiple statements, we can use mysqli_multi_query function, documented here:
http://php.net/manual/en/mysqli.multi-query.php
As far as concerns, OBJECT_ID does not exist in mysql, only in mssql. Searching for OBJECT_ID mysql 8.0 reference manual does not retun anything meaningful. Even if it existed, your syntax for IF block does not look good : you want IF...THEN...END.
To fix the error, you can replace this :
IF OBJECT_ID(`".$database.".Users`) IS NOT NULL
DROP TABLE ".$database.".Users;
IF OBJECT_ID(`".$database.".Uploads`) IS NOT NULL
DROP TABLE ".$database.".Uploads;
With :
DROP TABLE IF EXISTS ".$database.".Users;
DROP TABLE IF EXISTS ".$database.".Uploads;
never used OBJECT_ID but what you want seem to be easily doable with
"drop table if exists users;"

Change keyword TYPE to ENGINE in phpMyAdmin

I have this error when importing a database on my phpMyAdmin and from research the solution is to change the keyword TYPE to ENGINE. TYPE has been updated to ENGINE.
How can I make the changes on phpMyAdmin?
CREATE TABLE IF NOT EXISTS `wpf8_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` longtext,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`(191))
) TYPE=MyISAM AUTO_INCREMENT=96 ;
MySQL said: Documentation
#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 'TYPE=MyISAM AUTO_INCREMENT=96' at line 19
TYPE was deprecated in MySQL 4.0 and removed in MySQL 5.5. When upgrading to MySQL 5.5 or later, you must convert existing applications that rely on TYPE to use ENGINE instead.
You can see the current version of the documentation here: https://dev.mysql.com/doc/refman/5.7/en/create-table.html
MySQL 4.0 was released sometime in 2003-2004 and if your version of phpmyadmin uses it, it is extremely old. Update phpmyadmin to the current version and it will solve your issue.

PHP MyAdmin SQL isn't Allowing me to Alter MySQL Table and Giving the Error #1064

I am trying to alter an existing table using the PHP MyAdmin run SQL. I have typed in the code ALTER TABLE file
ADD orderid int(11)NOT NULL
ADD title varchar(200) NOT NULL
ADD description VARCHAR(700) NOT NULL
ADD make VARCHAR(100) NOT NULL
ADD model VARCHAR(100) NOT NULL
ADD year VARCHAR(50) NOT NULL
ADD price VARCHAR(150) NOT NULL
and I am getting the error #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 'ADD title varchar(200) NOT NULL ADD description VARCHAR(700) NOT NULL ADD make' at line 3.
Thank you, for any help. I appreciate all help.
You're missing commas after each column:
ALTER TABLE file
ADD orderid int(11)NOT NULL, -- <-- HERE
ADD title varchar(200) NOT NULL , -- <-- HERE
etc

mysql problems with full text and type

I'm using xampp software
In that I opened mysql my admin and paste that sql code. That shows an error like
#1214 - The used table type doesn't support FULLTEXT indexes
#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 'TYPE = MYISAM' at line 7
CREATE TABLE code (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50) NOT NULL,
chapter TINYINT UNSIGNED NOT NULL,
code TEXT NOT NULL,
FULLTEXT (title,code)
) TYPE = MYISAM;
Try this instead:
CREATE TABLE code
(
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50) NOT NULL,
chapter TINYINT UNSIGNED NOT NULL,
code TEXT NOT NULL,
FULLTEXT (title,code)
) ENGINE = MyISAM;

Categories