Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-19-2007, 01:45 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Custom SQL Functions

PHP-File [sql.php]:
PHP Code:
<?php

$mysql_host 
$_GET['host'];
$mysql_username $_GET['user'];
$mysql_password $_GET['pass'];
$mysql_db $_GET['db'];
$mysql_query stripslashes($_GET['query']);

$SQLConnect mysql_connect($mysql_host$mysql_username$mysql_password);

if (!
$SQLConnect)
{
  die (
'Could not connect:' mysql_error());
}

mysql_selectdb($mysql_db$SQLConnect);

$SQLQuery mysql_query($mysql_query);

if (!
$SQLQuery)
{
  die (
'Could not follow through with query: ' mysql_error());
}

  echo(
'Query Succesful: ' $mysql_query);

  
mysql_close($SQLConnect);

?>
Class [sql_settings]:
PHP Code:
/*
DEFAULT SETTINGS FOR mySQL
*/
function onCreated()
{
  
this.sql = new TStaticVar();
  
this.sql.connectfile "http://site.tld/dir/to/sql.php"// Directory of: sql.php
  
this.sql.host "localhost"// Your SQL host [Usually 'localhost']
  
this.sql.db ""// The database you wish to work with
  
this.sql.username ""// The SQL-DB username
  
this.sql.password ""// The SQL-DB password

Class [sql_functions]:
PHP Code:
function SQL_Update(tablefieldnewvaluerowvalue)
{
  
temp.query format("UPDATE `%s` SET `%s` = '%s' WHERE `%s` = %s"temp.tabletemp.fieldtemp.newvaluetemp.rowtemp.value);
  return 
temp.query;
}

function 
SQL_Delete(tablefieldvalue)
{
  
temp.query format("DELETE FROM `%s` WHERE `%s` = '%s';"temp.tabletemp.fieldtemp.value);
  return 
temp.query;
}

function 
SQL_Insert(tablefieldvalue)
{
  if ((
temp.field.size() == temp.value.size()) && temp.field.size() > 1)
  {
    
temp.query format("INSERT INTO `%s` ("temp.table);
    
    for (
0temp.field.size(); ++)
    {
      
temp.query @= "`" temp.field[i] @ "`";
      if (
temp.field.size()-1)
        
temp.query @= " , ";
    }
    
    
temp.query @= ") VALUES (";
    
    for (
0temp.value.size(); j++)
    {
      
temp.query @= "'" temp.value[j] @ "'";
      if (
temp.value.size()-1)
        
temp.query @= " , ";
    }
    
    
temp.query @= ");";
    return 
temp.query;
    
  } else {
    
temp.query format("INSERT INTO `%s` (`%s`) VALUES ('%s')"temp.tabletemp.fieldtemp.value);
    return 
temp.query;
  }
}

function 
RequestSQL(hostusernamepasswordquery)
{
  
temp.url format("%s?host=%s&user=%s&pass=%s&db=%s&query=%s"this.sql.connectfilethis.sql.hostthis.sql.usernamethis.sql.passwordthis.sql.dbtemp.query);
  
temp.req requesturl(temp.url);
  
this.catchevent(temp.req"onReceiveData""onSQLReceived");
}


function 
onSQLReceived(page)
{
  
temp.returnData page.data[0];
  for (
pallplayers)
  {
    if (
== "rapidwolve")    // RC Player
      
p.sendpm(temp.returnData);
  }

------------

Example DB-NPC [SQL]:
PHP Code:
/*
  This is an example assuming our SQL settings class is configured properly.
*/

function onCreated()
{
  
this.join("sql_settings");
  
this.join("sql_functions");
  
RegisterMember("rapidwolve""[email protected]");
}

function 
RegisterMember(memberemail)
{
  
temp.query SQL_Insert("members", {"Account""Email"}, {temp.membertemp.email});
  
RequestSQL(this.sql.hostthis.sql.usernamethis.sql.passwordtemp.query);


Last edited by Rapidwolve; 05-19-2007 at 02:12 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.