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.

what is the advantage of using sql builder?

y2kbgy2kbg New
edited January 2007 in Vanilla 1.0 Help
what is the advantage of using sql builder?

And how would i redo this to use sql builder?

function Friends_GetFriendStatusLists(){ global $Context; $selfID = $Context->Session->UserID; $Friends_FriendRequests = array( 'Friends_MyRequests_UserID'=>array(), 'Friends_MyRequests_FriendStatus'=>array(), 'Friends_RequestsToMe_UserID'=>array(), 'Friends_RequestsToMe_FriendStatus'=>array() ); $Friends_MyRequestsQuery = mysql_query("SELECT Friend, FriendStatus FROM LUM_Friends WHERE UserID = '$selfID'"); if (!$Friends_MyRequestsQuery) { die('Invalid query: ' . mysql_error()); } $Friends_RequestsToMeQuery = mysql_query("SELECT UserID, FriendStatus FROM LUM_Friends WHERE Friend = '$selfID'"); if (!$Friends_RequestsToMeQuery) { die('Invalid query: ' . mysql_error()); } $listcount = ''; while ($row = mysql_fetch_array($Friends_MyRequestsQuery)) { $Friends_FriendRequests['Friends_MyRequests_UserID'][$listcount]= $row['Friend']; $Friends_FriendRequests['Friends_MyRequests_FriendStatus'][$listcount]= $row['FriendStatus']; $listcount++; } $listcount = ''; while ($row = mysql_fetch_array($Friends_RequestsToMeQuery)) { $Friends_FriendRequests['Friends_RequestsToMe_UserID'][$listcount]= $row['UserID']; $Friends_FriendRequests['Friends_RequestsToMe_FriendStatus'][$listcount]= $row['FriendStatus']; $listcount++; } return($Friends_FriendRequests); }

Comments

  • Bump* I think people are having problem with my extension because of sql syntax and i believe using sql builder would fix this. I am correct?
  • so??????????? sorry bout the tri-post but doesn't anyone know anything about this?
  • in you case I think using sqlbuilder would just needlessly complicate things, as you'd have to add indices to the $DatabaseColumns and related arrays.
  • mmk thanks, so what about peoples syntax should it work version to version?
  • what do you mean by 'syntax'? mysql syntax or sqlbuilder? I would expect the calling conventions of the sqlbuilder class to stay the same for minor version differences, and mysql syntax would be dependant on the mysql version rather than the vanilla version.

    one thing, though. I would recommend using the database class to access mysql functions rather than simply calling them. It provides a nice wrapper allowing for more extensibility and better error management.
  • edited January 2007
    Yeah, sqlbuilder is really only meant to be used if Vanilla supported more than one database (i.e. MySQL and PostgreSQL). The only thing I can think of for your code is replacing "LUM_" with $Context->Configuration['DATABASE_TABLE_PREFIX']. Not everybody has the default prefix. Otherwise, you're alright.
  • I actually meant compatibility of my mysql syntax among anyone that might install my extension. would you elaborate please? = "database class" "The only thing I can think of for your code is replacing "LUM_" with $Context->Configuration['DATABASE_TABLE_PREFIX']." Will Do!!
  • NickENickE New
    edited January 2007
    I meant, instead of using the mysql_* functions directly, use the $Context->Database class to access the db. Eg. $Context->Database->Execute('query here', 'current class name', 'current function name', 'error message');
  • ohh for the pretty error report? or does it provide more benefit than error handeling?

    I will be sure to make this change either way way, Thanks for the tip!
This discussion has been closed.