Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Connecting to the database from an application

edited March 2010 in Vanilla 2.0 - 2.8
I'm trying to write an application for Garden and have run into a roadblock with the database.

The application works fine with basic HTML, but I need to connect to my database and display/manipulate the data.

I have this code in the application manage.php controller:
$DataSet = $Database->Select('Name')->From('GDN_User')->Get();

When I try to load the page myapp/manage, I'm getting this error:
Undefined variable: Database

Any help you can provide is greatly appreciated!


Comments

  • lucluc ✭✭
    As stated by the error, you need to create your Database object.

    Database = Gdn::Database();
    should do the trick.
  • Also you don't prefix the table in FROM with GDN_ as that is already set in the database class.
  • lucluc ✭✭
    True, I didn't really read the full comment, just the error part.
  • SS ✭✭
    Ho. Actually, you shouldn't use any data manipulation in application controller. Getting data from database (data manipulation in the general case) it is job for model.
Sign In or Register to comment.