Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Database Connection on extension.php when not signed in

edited July 2006 in Vanilla 1.0 Help
I try to make a database query on the extension.php when a user is not logged in, but I only get errors.

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
When a user is logged in all works fine...
$Context->PageTitle = $Context->GetDefinition('MyExtension'); $Menu->CurrentTab = 'MyExtension'; $Body->CssClass = 'MyExtensionContainer'; $Content = $Context->ObjectFactory->NewContextObject($Context, 'Content'); $Page->AddRenderControl($Content, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
and then
class Content { function Content() { global $Context; $res = mysql_query("SELECT ...",$Context->Database->Connection); $row = mysql_fetch_row($res); <<-- Here the error appears .... } }

I don't know what's wrong, because the query works fine when a user is logged in...

Comments

  • Options
    I actually got it work with this at the begin of the default.php, but there must be another way
    if (!$Context->Database->Connection) { $Context->Database->Connection = @mysql_connect($Context->Configuration['DATABASE_HOST'],$Context->Configuration['DATABASE_USER'],$Context->Configuration['DATABASE_PASSWORD']); @mysql_select_db($Context->Configuration['DATABASE_NAME'], $Context->Database->Connection); }
  • Options
    MarkMark Vanilla Staff
    Wierd. I don't remember ever explicitly killing the connection or not creating it for that page. It's just another standard page.
  • Options
    but without that code above it even gives an error message when I add an query somewhere outside the class it also doesn't work.
    If I remove the code and go (without logged in) to the account Page the queries work fine! Only at the extension Page they don't
  • Options
    MarkMark Vanilla Staff
    Well, it still doesn't make any sense to me since the connection is always opened on every page.

    But try this instead of your connection checking code:

    $Context->Database->GetConnection();

    That will check for a connection. If one isn't found, it will create it and you should be able to move forward properly.
This discussion has been closed.