Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

SQL quiries to external db?

Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-15-2007 07:54
can someone point me in the right direction. I want to have a in-world object access a database on my external hosted webserver and display results in-world.

I looked and xlm and the ||http stuff. Not sure that will work. Anyone else do this that can send me a snippit.

thx
falney Finney
Freedom is just a word
Join date: 18 Dec 2006
Posts: 66
05-15-2007 08:09
Im actualy wanting to do something similar....

you can find a simple database system using python here

http://www.notabene-sl.com/misc/silo-README.txt
http://www.notabene-sl.com/misc/silo.tgz

As for SQL you would need to do a lot of the coding in php I think.... (least thats the only way I can think of)

send a request through the http shiz to the php..... in say for instance your checking a universal access list for doors all over the grid... you would need a touch start on the door that gathers either the UUID, the avi name or both and send it to the back end script on your server... the script on your server will need to query the sql db and return a "true" value to SL if the name is onthe list....

If I am right.... *crosses fingers and hopes she doesnt jinx it* the sl coding wont be to hard and if your good with php then that will be dirt simple....

but Im not to great with php so Im going to have to research it... If you havnt managed it by the time I have Ill post what I did *smiles* if you finish it first fancy helping me out?
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
05-15-2007 08:46
For something simple like checking an access list:

access.php
CODE
<?php

$dbhost='localhost';
$dbuser='username';
$dbpass='password';
$dbname='somedatabase';

if(!@mysql_connect($dbhost,$dbuser,$dbpass))
die('Cannot connect');

if(!@mysql_select_db($dbname))
die('Cannot select DB');

if(!isset($_GET['uname']))
die('missing name');
$uname=$_GET['uname'];

$res=mysql_query('SELECT uname FROM access WHERE uname='.dbesc($uname)) or die('SQL failed');

if(mysql_num_rows($res)==0)
die('invalid');

die('valid'.$uname);

function dbesc($txt,$doubquotes=0){
return '"'.mysql_real_escape_string($txt).'"';
}

?>


Then call it from inworld like this:
CODE

default{
touch_start(integer t){
llHTTPRequest("http://mywebhost.com/access.php?uname=" + llEscapeURL(llDetectedName(0)), [HTTP_METHOD,"GET"], "");
}

http_response(key request_id, integer status, list metadata, string body){
if(llGetSubString(body,0,4)!="valid")
return;
string validname=llGetSubString(body,5,-1);
// do whatever you need to do with validname here
}
}


This would use a database with a table called "access", with a field called uname containing the username of anyone who is allowed access. Anyone not allowed access should not be listed in the table.

The lsl example above is lacking in certain optimizations. It doesn't handle multiple clicks in the same touch_start, and doesn't keep a list of those already verified, which leaves it open to abuse. Just modify it to keep a list of results for the last 50-100 clicks or so, then search that list before calling llHTTPRequest.
_____________________
Send me the last 4 digits of a valid SSN, I'll verify you are who you say you are, even if you aren't.
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-15-2007 12:26
great..I will go play with this.

what I am trying to do is (i think) much simpler...
I have a db with 30 widgets. I want to allow an avatar to touch an object and get a SUM of all widgets. I have the php code and it works on the website. I think your post will give me a good start.

Eventually, I would like to allow avatars to type in a NAME of a widget and retrieve the row info for that widget...baby steps :-)