How do i fix this problem ive tried alot? - php

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?

Related

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.

sql comment error

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 ''

Some problems in the creation of MySql tables in a PHP script [duplicate]

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
I am trying to install a php script for the statistic on my server.
This script use MySql as database. The problem is that, when I try to install it, seems that can't create the tables in the database and give me the following error message:
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 5
Query : CREATE TABLE phpmv_a_category ( id int(10) unsigned NOT NULL
auto_increment, name varchar(100) default NULL, PRIMARY KEY (id) )
TYPE=MyISAM
The tables are created in a php file in this way:
$create['a_category'] =
"CREATE TABLE ".DB_TABLES_PREFIX.'a_category'." (
id int(10) unsigned NOT NULL auto_increment,
name varchar(100) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM
";
Where is the problem?
Tnx
Andra
According to the manual, TYPE is deprecated and was replaced by ENGINE in MySQL 5.5: documentation for CREATE TABLE.
It's not TYPE but instead ENGINE
ENGINE=MyISAM
SQLFiddle Demo
You are missing a ";" after ENGINE=MyISAM.

forum module error

I have installed a forum module for SS. I'm currently using version 2.3.3
After I installed the forum file on the back end I receive a message that says “File not found” on Firefox, and “This webpage is not found” on Google Chrome.
I followed all the instructions but I still get the error message.
Also, when I run http://mysite.co.za/dev/build/?flush=1, I receive this error message
>[User Error]
Couldn't run query:
CREATE TABLE `ForumCategory` (
`ID` int(11) not null auto_increment,
`ClassName` enum('ForumCategory') character set utf8 collate utf8_general_ci default 'ForumCategory',
`Created` datetime,
`LastEdited` datetime,
`Title` varchar(100) character set utf8 collate utf8_general_ci,
`StackableOrder` varchar(2) character set utf8 collate utf8_general_ci,
`ForumHolderID` int(11) not null default '0',
index `ForumHolderID` (ForumHolderID),
index `ClassName` (ClassName), primary key (ID) ) TYPE=MyISAM
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 14
GET /dev/build/flush=1
Line 401 in /home/neutrog7/public_html/sapphire/core/model/MySQLDatabase.php"
Your best bet is to upgrade to a newer version of SilverStripe. I'd recommend upgrading to 3.0 if you can, but if it becomes too much effort to upgrade to 3.0 then try 2.4.
If you really can't upgrade at this stage, you'll need to replace "TYPE" with "ENGINE" in MySQLDatabase.php. But, really, you're going to be mostly on your own if you go down this path and upgrading would be much better.

MySQL Query Works on My Laptop, but Not on Server

I worked on a site locally through my Laptop. I have a table named blog and it has the fields post_id, title, markdown, author, added, and modified.
The fields Added and Modified are both DATETIME's.
When a user makes a blog post, PHP runs this query successfully: INSERT INTO blog (title, author, markdown, added) VALUES ('BLA', 'BLA', 'BLA', NOW())
I've gone into phpMyAdmin and ran the exact same query with working results.
Now, I exported my exact database into the server today and I noticed that no posts were being stored in the DB, so I tried running it through phpMyAdmin's SQL and it gave me the error Field 'modified' doesn't have a default value.
Why would this be happening? In my database, the default for both is None so I'm quite confused on what could be causing this.
My Laptop has PHP 5.3.1 and MySQL 5.1.41 (I installed XAMPP.)
The Server has PHP 5.3.5 and MySQL 5.5.8 (Out of desperation I installed the newest versions. The server was originally running MySQL 5.1 and a lower version of PHP.)
This has been killing me, hopefully someone knows what's wrong with this or how to fix it.
Edit: Here are the SHOW CREATE TABLE blog results.
Laptop:
| blog | CREATE TABLE `blog` (
`post_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`title` varchar(160) NOT NULL,
`author` varchar(100) NOT NULL,
`markdown` longtext NOT NULL,
`added` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 |
Server:
| blog | CREATE TABLE `blog` (
`post_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`title` varchar(160) NOT NULL,
`author` varchar(100) NOT NULL,
`markdown` longtext NOT NULL,
`added` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 |
Auto Increments are different because of my tests.
ALTER TABLE blog CHANGE modified modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
Or, more rarely, you might have a buggy version of MySQL on your server.
*I might have the syntax imperfect, I referred to the last comment on ALTER TABLE at the bottom of the manual page.
First: are you sure the data on your laptop exactly the same as the data on the server? Maybe you're not getting this error on your laptop because the default values are set on your laptop table somehow and not the server -- possibly an issue with how you exported the data.
When you say, the default is "None" do you mean NULL or do you mean literally the word "None"?
If both fields are datetime fields, then set the default to NOW() or, if you prefer to not have an actual date and time by default, use a string like "0000-00-00 00:00:00", or the JDBC friendly "0001-01-01 00:00:00".
Compare the structure of each table with the following command in a mysqlclient:
SHOW CREATE TABLE blog;
Dump the DDL from both versions using
$ mysqldump --no-data dabasename
and compare them (and check the man page for mysqldump(1) as I'm flying by memory here.)
Make sure you're using the same exact table description and that both versions are using the same engine.

Categories