vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Mod Create new Table.. (https://vborg.vbsupport.ru/showthread.php?t=167910)

John3971 01-16-2008 04:26 PM

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?

Opserty 01-16-2008 05:22 PM

Just Google "MySQL Create Table" you will get loads of tutorials/guides and the official documentation.

Andrew Green 01-16-2008 05:35 PM

$db->query_write("CREATE TABLE test (testid integer NOT NULL PRIMARY KEY auto_increment, testname text)");

John3971 01-16-2008 06:18 PM

Quote:

Originally Posted by Andrew Green (Post 1422611)
$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


Opserty 01-16-2008 06:30 PM

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.

John3971 01-16-2008 06:51 PM

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


Andrew Green 01-16-2008 06:55 PM

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)");

John3971 01-16-2008 07:05 PM

Quote:

Originally Posted by Andrew Green (Post 1422641)
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


petteyg359 01-16-2008 07:08 PM

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).

John3971 01-16-2008 07:15 PM

Quote:

Originally Posted by petteyg359 (Post 1422650)
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


All times are GMT. The time now is 12:27 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01032 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete