Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2008, 04:26 PM
John3971 John3971 is offline
 
Join Date: Sep 2007
Location: Sweden
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Mod Create new Table..

Hey im working on a plugin and i want this plugin to create a new table in the database and i don´t know how i should get it work i only get error so can somebody give the code that creates a new table that i can put in?
Reply With Quote
  #2  
Old 01-16-2008, 05:22 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just Google "MySQL Create Table" you will get loads of tutorials/guides and the official documentation.
Reply With Quote
  #3  
Old 01-16-2008, 05:35 PM
Andrew Green's Avatar
Andrew Green Andrew Green is offline
 
Join Date: Nov 2005
Location: Winnipeg, MB
Posts: 996
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$db->query_write("CREATE TABLE test (testid integer NOT NULL PRIMARY KEY auto_increment, testname text)");
Reply With Quote
  #4  
Old 01-16-2008, 06:18 PM
John3971 John3971 is offline
 
Join Date: Sep 2007
Location: Sweden
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andrew Green View Post
$db->query_write("CREATE TABLE test (testid integer NOT NULL PRIMARY KEY auto_increment, testname text)");
that was the one i had but i keep getting this error when im importing the plugin:

Code:
Database error in vBulletin 3.7.0 Beta 3:

Invalid SQL:
CREATE TABLE vb_news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, date date, time time, poster varchar, text text);

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 ' date date, time time, poster varchar, text text)' at line 1
Error Number  : 1064
Date          : Wednesday, January 16th 2008 @ 09:17:28 PM
Script        : http://test.fanrage.org/testvb/admin/plugin.php?do=productimport
Referrer      : http://test.fanrage.org/testvb/admin/plugin.php?do=productadd
IP Address    : 85.224.63.34
Username      : John
Classname     : vB_Database
MySQL Version : 5.0.18-nt-log
Reply With Quote
  #5  
Old 01-16-2008, 06:30 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

date and time are MySQL keywords I think and also text. Make sure the column names aren't the same as the column types. Also enclose the column names in single quotes.
Reply With Quote
  #6  
Old 01-16-2008, 06:51 PM
John3971 John3971 is offline
 
Join Date: Sep 2007
Location: Sweden
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i tried this now
Code:
$db->query_write("CREATE TABLE " . TABLE_PREFIX . "news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, date varchar, time varchar, poster varchar, newst text)");
but it still doesn?t work i get this error:
Code:
Database error in vBulletin 3.7.0 Beta 3:

Invalid SQL:
CREATE TABLE vb_news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, date varchar, time varchar, poster varchar, newst text);

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 ' date varchar, time varchar, poster varchar, newst text)' at line 1
Error Number  : 1064
Date          : Wednesday, January 16th 2008 @ 09:49:56 PM
Script        : http://test.fanrage.org/testvb/admin/plugin.php?do=productimport
Referrer      : http://test.fanrage.org/testvb/admin/plugin.php?do=productadd
IP Address    : 85.224.63.34
Username      : John
Classname     : vB_Database
MySQL Version : 5.0.18-nt-log
Reply With Quote
  #7  
Old 01-16-2008, 06:55 PM
Andrew Green's Avatar
Andrew Green Andrew Green is offline
 
Join Date: Nov 2005
Location: Winnipeg, MB
Posts: 996
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can't name a field "date" or "time", you need to rename those, ex:

Code:
$db->query_write("CREATE TABLE " . TABLE_PREFIX . "news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, newsdate varchar, newstime varchar, poster varchar, newst text)");
Reply With Quote
  #8  
Old 01-16-2008, 07:05 PM
John3971 John3971 is offline
 
Join Date: Sep 2007
Location: Sweden
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andrew Green View Post
You can't name a field "date" or "time", you need to rename those, ex:

Code:
$db->query_write("CREATE TABLE " . TABLE_PREFIX . "news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, newsdate varchar, newstime varchar, poster varchar, newst text)");
aa then i understand :P

but i still get error when i use the one you wrote here.

Code:
Database error in vBulletin 3.7.0 Beta 3:

Invalid SQL:
CREATE TABLE vb_news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar, newsdate varchar, newstime varchar, poster varchar, newst text);

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 ' newsdate varchar, newstime varchar, poster varchar, newst text)' at line 1
Error Number  : 1064
Date          : Wednesday, January 16th 2008 @ 10:04:39 PM
Script        : http://test.fanrage.org/testvb/admin/plugin.php?do=productimport
Referrer      : http://test.fanrage.org/testvb/admin/plugin.php?do=productadd
IP Address    : 85.224.63.34
Username      : John
Classname     : vB_Database
MySQL Version : 5.0.18-nt-log
Reply With Quote
  #9  
Old 01-16-2008, 07:08 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Varchar type requires a length. Not optional.

Code:
CREATE TABLE vb_news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar(128), newsdate varchar(10), newstime varchar(10), poster varchar(32), newst text);
Assuming your date is no more than MM/DD/YYYY (fuzzy/verbose dates would need a longer string), and time can be at most HH:MM:SSPM unless you make that number bigger too. 10 on time should be enough for very fuzzy times, too (yesterday, and 1 hour ago - 9 hours ago both work, but anything minutes wouldn't).
Reply With Quote
  #10  
Old 01-16-2008, 07:15 PM
John3971 John3971 is offline
 
Join Date: Sep 2007
Location: Sweden
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by petteyg359 View Post
Varchar type requires a length. Not optional.

Code:
CREATE TABLE vb_news (id integer NOT NULL PRIMARY KEY auto_increment, title varchar(128), newsdate varchar(10), newstime varchar(10), poster varchar(32), newst text);
Assuming your date is no more than MM/DD/YYYY (fuzzy/verbose dates would need a longer string), and time can be at most HH:MM:SSPM unless you make that number bigger too. 10 on time should be enough for very fuzzy times, too (yesterday, and 1 hour ago - 9 hours ago both work, but anything minutes wouldn't).
now it worked thanks alot. i really suck on mysql

--------------- Added [DATE]1200518572[/DATE] at [TIME]1200518572[/TIME] ---------------

okey got another question related to this.
i want the date to be saved like MM/DD/YYYY but i want it to be shown as the option says in acp. like this: 1st January 2008
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:41 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04825 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete