Symfony: creating invalid MySQL code? - php

I'm reading the Symfony documentation (Practical Symfony), and I finished creating the SQL code with propel.
But when i try to
$ symfony propel:insert-sql
the MySQL complains with:
#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=InnoDB' at line 7
Snippet of the produced MySQL code:
CREATE TABLE `jobeet_category` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 255 ) ,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `jobeet_category_U_1` ( `name` )
) TYPE = InnoDB;
So the problem is TYPE = InnoDB;, but I don't understand why did propel produce invalid code.
I followed all the instructions in the book, I'm not sure what could be the problem - maybe the MySQL version I have?
Edit: I found my answer. http://zippykid.com/2010/05/symfony-mysql5-5-error/

I'm pretty sure it should be ENGINE = InnoDB instead of type.

Related

SQL Table Error Magento

This is very odd, anyone have an answer for why this gives an error?
------------------------------------------------------ --
--
-- Table structure for table `mg_cataloginventory_stock`
--
CREATE TABLE IF NOT EXISTS `mg_cataloginventory_stock` (
`stock_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Stock Id',
`stock_name` VARCHAR( 255 ) DEFAULT NULL COMMENT 'Stock Name',
PRIMARY KEY ( `stock_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Cataloginventory Stock';
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 '--------------------------------------------------------
--
-- Table structu' at line 1
It appears that your SQL comment syntax is incorrect.
From a “-- ” sequence to the end of the line. In MySQL, the “-- ” (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).
It should be something like this:
-- ------------------------------------------------------
--
-- Table structure for table `mg_cataloginventory_stock`
--

oci_execute(): OCI_SUCCESS_WITH_INFO: ORA-24344 using a trigger/sequence to auto increment an oracle table error

I'm using a sequence and trigger to essentially auto increment a column in a table, however I'm getting an error - ORA-24344: success with compilation error.
I was using this post: How to create id with AUTO_INCREMENT on Oracle? and it worked successfully for two other tables w/ auto increment I made, but there must be something in here I'm not familiar with causing an error.
More edits: Thanks to Polppan we've established that this likely isn't an Oracle issue, rather an OCI with PHP issue. I'm using:
oci_execute($sql);
And as mentioned here (again, thanks Polppan for that link), there's a bit of an issue between EOL characters and oci_execute. It was 11 years ago, so I don't know if that's been patched or not, and I did try his solution but it didn't help. Does anyone know if there are other issues with oci_execute and creating triggers?
Creating the table: (works)
CREATE TABLE RT_documents (
documentID INT NOT NULL,
reviewID varchar2(20) NOT NULL,
file_location CLOB NOT NULL,
version NUMBER(*,3) NOT NULL,
CONSTRAINT RT_documents_pk PRIMARY KEY (documentID)
)
Creating the sequence: (works)
CREATE SEQUENCE rt_documents_seq
Creating/replacing trigger: (doesn't work)
CREATE OR REPLACE TRIGGER rt_documents_bir
BEFORE INSERT ON RT_documents
FOR EACH ROW
BEGIN
SELECT RT_documents_seq.NEXTVAL
INTO :new.documentID
FROM dual;
END;
EDIT: Exact error message as requested - (Note, I'm executing these query-by-query using OCI/Oracle in PHP. PHP tag added just in case, but pretty sure this is an oracle syntax error or something).
Error:
Notice: oci_execute(): OCI_SUCCESS_WITH_INFO: ORA-24344: success with
compilation error in (...)
-I can successfully execute the first two queries, and double checked and the table is there so it worked properly.
Trigger doesn't understand new.id as id doesn't exist in RT_documents table.
Your trigger should be
CREATE OR REPLACE TRIGGER rt_documents_bir
BEFORE INSERT
ON RT_documents
FOR EACH ROW
BEGIN
SELECT RT_documents_seq.NEXTVAL INTO :new.documentID FROM DUAL;
END;
Update
SELECT * FROM v$version;
Oracle Database 10g Enterprise Edition
CREATE TABLE RT_documents
(
documentID INT NOT NULL,
reviewID VARCHAR2 (20) NOT NULL,
file_location CLOB NOT NULL,
version NUMBER (*, 3) NOT NULL,
CONSTRAINT RT_documents_pk PRIMARY KEY (documentID)
);
Table created.
CREATE SEQUENCE rt_documents_seq;
Sequence created.
CREATE OR REPLACE TRIGGER rt_documents_bir
BEFORE INSERT
ON RT_documents
FOR EACH ROW
BEGIN
SELECT RT_documents_seq.NEXTVAL INTO :new.documentID FROM DUAL;
END;
/
Trigger created.
INSERT INTO RT_documents (reviewID, file_location, version)
VALUES ('test', 'test', 1);
1 row created.
SELECT * FROM RT_documents;
DOCUMENTID REVIEWID FILE_LOCATION
VERSION
---------- -------------------- -------------------------------------------
-------------------------------- ----------
1 test test
1
Thanks to Polppan.
The solution was removing the EOL characters. (I did try this but had, without realising, removed the semi-colons, which caused the same error code)
This was a PHP error after all. Using oci_execute, you must remove EOL characters in triggers:
$sql = "CREATE OR REPLACE TRIGGER ......."; //shortened for easy reading
$sql = str_replace(chr(13),'',$sql);
$sql = str_replace(chr(10),'',$sql);
oci_execute($sql);

mySQL error: You have an error in your SQL syntax (ENGINE=MyISAM)

At the first time I got such error, I realize the problem was similar to this question > Error #1064 in mysql So I changed the TYPE=MyISAM on my code to ENGINE=MyISAM.
But even after the changing, I encountered similar error. It says,
mySQL error: 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 '(14),
PRIMARY KEY (id)
) ENGINE=M' at line 7.
I thought changing to ENGINE=MyISAM would fix the error, but it doesn't. What should I do?
Here is my code:
$queries[] = "CREATE TABLE IF NOT EXISTS {$prefix}conversationlog (
id int(11) NOT NULL auto_increment,
input text default '',
response text default '',
thatresponse text default '',
uid varchar(255) default NULL,
enteredtime timestamp(14),
PRIMARY KEY (id)
) ENGINE=MyISAM";
The error is at the (14), not ENGINE=MyISAM. The TIMESTAMP type does not take a size; it's always timestamp-sized.

mysql error 'TYPE=MyISAM'

Below query I'm executing in Ubuntu 12, MySQL 5.1 version and receiving error as mentioned:
CREATE TABLE mantis_config_table (
config_id VARCHAR(64) NOT NULL,
project_id INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL DEFAULT 0,
access_reqd INTEGER DEFAULT 0,
type INTEGER DEFAULT 90,
value LONGTEXT NOT NULL,
PRIMARY KEY (config_id, project_id, user_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 9
Can anyone suggest what's wrong?
Replace
TYPE=MyISAM
with
ENGINE=MyISAM
The problem was "TYPE=MyISAM" which should be "ENGINE=MyISAM" as per MySQL version updates - a simple search / replace has fix it.
Do not use the keyword TYPE anymore. Use ENGINE instead.
TYPE keyword is depreciated (since 5.0) and not supported in MySQL5.5
CREATE TABLE mantis_config_table
(
...
)
ENGINE = MyISAM;
^^^^^^--------------------- HERE
In newer MySQL Versions its:
ENGINE=MyISAM
here the tutorial (MySQL)
Use ENGINE instead of TYPE
ENGINE = MYISAM ;

php mysql error for creating a table

I got an error while creating a table in php with mysql database, and I tried testing directly on mysql query engine it works fine. whereas in php code it gives below error
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.
Below is the code I am writing
$query14 = mysql_query("create table $tablename (
project_id INT,
project_client_id INT,
project_partner_id INT,
project_manager_id INT,
project_employees INT,
project_name VARCHAR(500),
project_status TEXT,
project_summary LONGTEXT,
project_order INT,
project_start_date DATETIME,
project_end_date DATETIME
) ENGINE = INNODB;");
and below is the image attached and table structure should be and this is the sample table i create using with phpmyadmin interface.
And below is the full error
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 ''8' (project_id INT, project_client_id INT, project_partner_id INT, project_mana' at line 1`
I didn't see any problem with your query. But what is the value of $tablename? Two error possibilities here :
The variable $tablename is empty.
$tablename is a key-word.
Please check the above two otherwise its all right.
UPDATE :
As per your updated question please try with the following code. I think it will help you.
$query14 = mysql_query("create table `$tablename` (
`project_id` INT,
`project_client_id` INT,
`project_partner_id` INT,
`project_manager_id` INT,
`project_employees` INT,
`project_name` VARCHAR(500),
`project_status` TEXT,
`project_summary` LONGTEXT,
`project_order` INT,
`project_start_date` DATETIME,
`project_end_date` DATETIME
) ENGINE = INNODB;");
Your query syntax is fine, it looks like $tablename is empty.
I think the issue is what is getting replaced for $tablename.
Having the full code example would be more useful in debugging the error.
The mysql create statement works just fine here on mysql 5.1.58 .
As you said in above comments that after echoing the $tablename you got the value 8 then it is not possible to create table.
you have to rename the value of $tablename like tbl_8.
remember with the name tbl-8 your also got error,,
The problem is, $tablename is 8 currently and for SQL table, table name must start with a letter. Current tablename is invalid.

Categories