query problem (delimiter?)

Reply

Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

query problem (delimiter?)

 
0
  #1
May 3rd, 2007
I have a program which requires a database. So I made a file that could generate the sql to create it (I copied the sql from PHPmyadmin as reference). When I execute the sql I get the error:
  1. 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 '; USE `anonymusiusform`; -- ------------------------------------------------' at line 4
It's always on the first ; that the error occurs. If I execute it in PHPmyadmin it works and correctly creates the database. I think the problem lays with the 'delimiter'. I tried googling it but I didn't found anything to solve my problem. This is the sql my file generate“s:
  1. -- -- Database: `anonymusiusform` -- CREATE DATABASE `anonymusiusform` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `anonymusiusform`; -- -------------------------------------------------------- -- -- Table structure for table `enquete` -- CREATE TABLE IF NOT EXISTS `enquete` ( `id` int(5) NOT NULL auto_increment, `ip` varchar(16) NOT NULL, `host` varchar(50) NOT NULL, `age` varchar(2) NOT NULL, `name` varchar(50) NOT NULL, `rank` varchar(8) NOT NULL, `opmerking` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Any help would be highly appreciated. Edit: The layout seems messed up, I don't get what's wrong. Sorry about it. It doesn't seems to recognize enters anymore.
Last edited by Anonymusius; May 3rd, 2007 at 9:30 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 3
Reputation: nsstone is an unknown quantity at this point 
Solved Threads: 0
nsstone nsstone is offline Offline
Newbie Poster

Re: query problem (delimiter?)

 
0
  #2
May 4th, 2007
Hmmm.. how about removing the superfluous comment detritus ... try:

CREATE DATABASE `anonymusiusform`
DEFAULT CHARACTER SET latin1
COLLATE latin1_swedish_ci;
USE `anonymusiusform`;
CREATE TABLE IF NOT EXISTS `enquete` (
`id` int(5) NOT NULL auto_increment,
`ip` varchar(16) NOT NULL,
`host` varchar(50) NOT NULL,
`age` varchar(2) NOT NULL,
`name` varchar(50) NOT NULL,
`rank` varchar(8) NOT NULL,
`opmerking` text NOT NULL,
PRIMARY KEY (`id`) )
ENGINE=InnoDB
DEFAULT CHARSET=latin1
AUTO_INCREMENT=1 ;
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: query problem (delimiter?)

 
0
  #3
May 4th, 2007
I removed the comments (they were just for fun there, and with enters it actually looked more structured) and it didn't seem to work, still the same error. I google'd a few times and searched through the mysql documentation but I didn't found anything that solve's this. Any help is highly appreciated. Here is the query again, and this time better formatted :
  1. --
  2. -- Database: `anonymusiusform`
  3. --
  4.  
  5. CREATE DATABASE `anonymusiusform` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
  6. USE `anonymusiusform`;
  7.  
  8. -- --------------------------------------------------------
  9.  
  10. --
  11. -- Table structure for table `enquete`
  12. --
  13.  
  14. CREATE TABLE IF NOT EXISTS `enquete` (
  15. `id` int(5) NOT NULL auto_increment,
  16. `ip` varchar(16) NOT NULL,
  17. `host` varchar(50) NOT NULL,
  18. `age` varchar(2) NOT NULL,
  19. `name` varchar(50) NOT NULL,
  20. `rank` varchar(8) NOT NULL,
  21. `opmerking` text NOT NULL,
  22. PRIMARY KEY (`id`)
  23. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I traced the enter problem down to me not enabling javascript because the site is dogslow (for me) with javascript enabled. So again sorry for my previous post.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: query problem (delimiter?)

 
0
  #4
May 6th, 2007
I made it work, my solution is however not so pretty looking:
[php]$query = '--
-- Database: `anonymusiusform`
--

CREATE DATABASE `anonymusiusform` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `anonymusiusform`;

-- --------------------------------------------------------

--
-- Table structure for table `enquete`
--

CREATE TABLE IF NOT EXISTS `enquete` (
`id` int(5) NOT NULL auto_increment,
`ip` varchar(16) NOT NULL,
`host` varchar(50) NOT NULL,
`age` varchar(2) NOT NULL,
`name` varchar(50) NOT NULL,
`rank` varchar(8) NOT NULL,
`opmerking` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
mysql_connect('localhost', 'username', 'password');

foreach(explode(';', $query) as $value)
{
if($value == ''){continue;}

mysql_query($value) or die(mysql_error());
}[/php]
It works now, I only use the application and it is only in the adminscreen so I will always be able to dump sql in case of a crash in phpmyadmin. If someone has a better solution please tell me.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: query problem (delimiter?)

 
0
  #5
May 6th, 2007
seems like you got it working then. if you have any more questions, don't hesitate to post!
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC