Trying to create db structure using db object (Gdn::Structure()) but "varchar" type is not working
Howdy!
Here is my code:public function Setup()
{
$Structure = Gdn::Structure();
$Structure->Table('TestPlugin')
->Column('Number', 'int(11)', FALSE, 'primary')
->Column('Email', 'varchar', '200')
->Set(TRUE, FALSE);
}
This code gives me this error.
but if I use "TEXT" instead of varchar, everything is working. But I wanna go with varchar and according to this doc I think I'm sure there are no any syntax errors in my code right?
If you guys can help me to figure out this issue, that will be a great help to me and I really appreciate it
Best Answers
-
Shadowdare MVP
The Column method's parameter list has changed. This is the outdated parameter list shown in the documentation you linked to:
public function Column( $Name, $Type, $Length = '', $Null = FALSE, $Default = NULL, $KeyType = FALSE, $AutoIncrement = FALSE )
In Vanilla 2.0.18.11, it's:
public function Column( $Name, $Type, $NullDefault = FALSE, $KeyType = FALSE )
With this in mind, using the varchar type would look like this:
->Column('Email', 'varchar(200)')
The documentation you linked to is outdated and will be replaced with the new documentation located at: http://docs.vanillaforums.com/
Add Pages to Vanilla with the Basic Pages app
10 -
R_J Admin
Try
$DataSet = Gdn::SQL()->Select('Users')->From($PluginTable)->Get()->ResultArray();
I guess that willgive you the result you are searching for.2
Answers
Vanilla core 2.0.18.11
The Column method's parameter list has changed. This is the outdated parameter list shown in the documentation you linked to:
In Vanilla 2.0.18.11, it's:
With this in mind, using the varchar type would look like this:
->Column('Email', 'varchar(200)')
The documentation you linked to is outdated and will be replaced with the new documentation located at: http://docs.vanillaforums.com/
Add Pages to Vanilla with the Basic Pages app
@Shadowdare
Thanks and it worked
But, the new documentation also have the same instructions in this link: http://docs.vanillaforums.com/developers/framework/database/
where did you find that stuff? will you give me the exact location?
You can get a lot of information simply by looking at Vanillas source code: https://github.com/vanilla/vanilla/blob/2.0/library/database/class.databasestructure.php#146-160
same as r_j pointed out line 95 but delving further... shows
from the preg match you can see the Type length must be in parenthesis in the Type field.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Guys
I've been trying this for the whole day and I am really tired of finding out about how this DB Class works. there is no any correct documentation about using the DB Object and it was really pain full to me. Please some one tell me how to run a select query using the Database Object and get those results to array.
This is all I found, and this also gives me some useless output
$DataSet = Gdn::SQL()->Select('Users')->From($PluginTable)->Get()
print_r ($DataSet);
Its show me:
object(Gdn_DataSet)[80]
public 'Connection' =>
object(PDO)[30]
private '_Cursor' => int -1
protected '_DatasetType' => string 'object' (length=6)
protected '_EOF' => boolean false
private '_PDOStatement' =>
object(PDOStatement)[44]
public 'queryString' => string 'select Domain
from GDN_BanDisposableMails BanDisposableMails' (length=60)
protected '_Result' => null
I just need the results guys I really need help.
Try
$DataSet = Gdn::SQL()->Select('Users')->From($PluginTable)->Get()->ResultArray();
I guess that willgive you the result you are searching for.
By the way: it might tiring to work through the code, but once you have the correct class, it's really worth looking at the functions in there. Most of the function names are speaking for themselves and so you don't have to study the source
@R_J oh finally that worked and you saved me
Thanks x1000 times.
hmmm yeah but where is that Gdn::SQL class located? (.php file?)
https://github.com/vanilla/vanilla/blob/master/library/database/class.sqldriver.php
this one?
Best is to use the file on your hard drive but it's easier to reference to GitHub from here (but then it is more save to include the right branch: https://github.com/vanilla/vanilla/blob/2.1/library/database/class.sqldriver.php)
Good to know, even if it was a bad idea to change the method, breaking backward compatibility...
My shop | About Me