Thread: SQL Help
View Single Post
  #2  
Old 09-25-2011, 03:31 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
My preferred method is to create a DB-NPC called SQL.

PHP Code:
/**
    SQL Query Interface
*/

public function executeSQL(query, result, doecho) {
  
temp.init = timevar2;
  
temp.results = requestsql(query, result);
  if (
result) {
    
// Check Results
    
if (results.error != "") {
      echo(
format("SQL Error: %s", results.error));
      
savelog2("sqlerrors.txt", results.error NL query);
      return 
NULL;
    }
    else if (
results.rows.size() > 0 || query.starts("SELECT")) {
      if (
doecho) echo(format("SQL returned %s rows.", results.rows.size()));
    }
    else if (
results.affectedrows.size() > 0) {
      if (
doecho) echo(format("SQL affected %s rows.", results.affectedrows.size()));
    }
    else if (
results.completed) {
      if (
doecho) echo(format("SQL %s Query completed successfully.", query.tokenize()[0].upper()));
    }
    
temp.taken = timevar2 - temp.init;
    
// Uncomment to log queries (for checking performance, etc.)
    //savelog2("sqlqueries.txt", query NL "Took " @ temp.taken @ " seconds");
    
return results;
  }
} 
Then in my server-side code I can do the following:

PHP Code:
function onCreated() {
  
temp.query = "SELECT Username,Password,EZ,Level,X,Y,Exp FROM Accounts";
  
temp.result = SQL.executeSQL(temp.query, true);
  if (
temp.result.rows.size() > 0) {
    for (
temp.row: temp.result.rows) {
      echo(
temp.row.Username);
    }
  }
} 
I threw this together quickly thought so I can't guarantee it'll work for your situation.

There's some other links here:
http://public.zodiacdev.com/index.ph...ntro_to_SQLite
__________________
Quote:
Reply With Quote