Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

php & MySQL – Beginner guidance – Storage and Recovery

Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
07-09-2008 16:11
php & MySQL – Beginner guidance – Storage and Recovery

The experienced and inexperience repeatedly recommend and urge me to look into using MySQL. I barely, and I cannot stress this enough, “barely” know how to use php let alone MySQL. I was going to save anywhere from 100 records upwards to 1000s of records using individual text files that a php script would make. The script I was toying with that that was an example I altered slightly was what I was planning to use for the Storage/Saving method.

To understand the php script on some level, I used a free website and host. To have
MySQL it looks like I will have to shell out some money although a small amount and would want to be able to actually use it and not look at the php manual online and the MySQL website and scratch my head as I have been doing.

From my understanding MySQL on a website would be accessible through a webpage and not from a program from my home computer. At least that is what one hosting site said. It really isn’t a huge deal as long as it just works and I can look at the data or change it on some rare occasion.

Below is the simple php script I was planning to use to create the log file for individuals records. If anyone would show me what a very simple script like this would look like if it was to tell MySQL to save an entry it might help be able to start somewhere.

The information being sent is a string like this “DragonMuir,00000,00000,34,23,4,3,5,89,2,3,4,53,4” Each “,” separates a single piece of data. All the data relates to “DragonMuir” All that I need is to be able to send that information, for it to be stored online, and if requested sometimes, to tell SL the last or current entry made to update the information in SL if a new item is created to replace the old or to restore the information when that scripted item is destroyed or malfunctions.

If anyone can find it in their hearts to mentor me or help me here with some example or guidance I would be very grateful, because unless I have this ability I cannot complete the project I have been working on.
^.=.^




From: someone

string url = "http://www.ExampleWebsite.com/test.php?search=";
string savedgameinformation;


//SAVE--------------------------------------------------------------SERVER

// get data back and process it
http_response(key request_id, integer status, list metadata, string body)
{
if (body == "Error: Cannot open file.";)
{
llOwnerSay(body + " please check your webserver and logfile";);
}

else if (body == "data saved";)
{
llSay(0,"Your Game data has been saved";);
}
end();
}

timer()
{
llSay(0,"server timeout, please try again in a moment";);
end();
}
//SAVE--------------------------------------------------------------SERVER












<?php

$search = $_GET["search"];
$filename = substr($search,0,25).".dta";
$user_data = file($filename);


// if its not write the name in the file
{
$fp = fopen($filename,"a+";);

// if your server cannot access the file error
// almomst any php server can make a file if one does not exist
// even if your server will not create a file for you
// you can place an empty file for the script to use
// you really have to screw up to get this error
if(!$fp)
{
echo "Error: Cannot open file.";
exit;
}

fwrite($fp,$search."\n";);
fclose($fp);
echo "data saved";
}
?>
Commander Quandry
Registered User
Join date: 23 Jun 2008
Posts: 1
07-10-2008 02:16
I am no PHP expert, however I know databases well and will happily help you where I can.

One note, you said:-

From: someone
From my understanding MySQL on a website would be accessible through a webpage and not from a program from my home computer. At least that is what one hosting site said. It really isn’t a huge deal as long as it just works and I can look at the data or change it on some rare occasion.


You can access your MySQL data from desktop applications, you could even host it on your household computer and not have to pay anyone. There are also some very good desktop applications to FrontEnd manage your data.

CQ
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
07-11-2008 09:32
I was in your position about a year ago. I know enough now to make it all work but I would still regard myself as a raw beginner despite 49 years of assembly language programming experience.

Implementing MYSQL and .php on a website depends on the host and what they support so that is the first line of attack. I had to move my website from a microsoft host to a UNIX host that supported both these requirements and you may also have to request that they be turned on. I'm using 1&1. They are inexpensive and reasonably helpful on the third help request. (The first two will just get boilerplate responses based on keywords.)

Then access the help files provided by the host to determine what addresses you need to set up in the .php to access the data base.

Accessing from a web page is fairly simple. Accessing from objects in Second Life is more difficult. Do not use XML and at this stage only HTTP requests from SL are available. There is work being done on HTTP access TO SL but no ETA yet.

I've not tried direct access from a computer without using a web page but it should be fairly easy if you have access to the computer program for setting the required MYSQL parameters.

The .php access programs on mine looks like this.

<?php

$server= "db######.xyz.net"; /* Address of database server */
$user= "dbo#######"; /* Database username */
$password= "password"; /* Database Password */
$database= "db######"; /* name of database */

/* Accessing SQL-server */
MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>";);
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>";);

php code goes here

echo xxxx; //to return data

MYSQL_CLOSE();
?>