Shoutbox

Connecting to a online SQL dabatase - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Connecting to a online SQL dabatase (/showthread.php?tid=73280)

Connecting to a online SQL dabatase by LifelesS on 04-03-2007 at 06:19 PM

Hi everyone :)

How can I connect to a SQL Database online? Do I need to make some DLL for acessing it?

I saw a topic moreless about it, but didn't understand it very well.

Can anyone give a hand?;)


RE: Connecting to a online SQL dabatase by absorbation on 04-03-2007 at 07:00 PM

Personally I would use PHP to connect to an online MySQL database. You can send information to a PHP script from your computer using the server variables $_POST and $_GET. If you understand what I am on about the amount of code required is rather small, and the task itself is easier than it sounds (if you understand what I meant).

If you don't get what I'm on about, I'm sure I can find you some live examples.


Edit: I've made an example for you :).


OK then this is easier than it may appear. First set up your database, customise it, there are no limitations, do as you wish. Next we need to get your script talking to your PHP script:

code:
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://www........", true);
http.send ("?sex=male&name=absorbation&address=fakestreet&dob=00.01.01");

Note: Change the url to wherever your script is located. Also &variable='variable data' is what your $_POST variable will be called and the data it will contain.


Finally we need to set up the PHP to communicate with the database:

code:
<?PHP
// Make sure you are connected to the database, and validate the data to make sure people don't abuse your script.
// Getting data sent to the server from the script. The varibles below will be used in the MySQL query.

$sex = $_POST['sex'];
$name = $_POST['name'];
$address = $_POST['address'];
$dob = $_POST['dob'];

// Display the data to make sure it is working.

echo "$sex<br />$name<br />$address<br />$dob";

// MySQL query, make sure you change the query to match your database.

mysql_query("insert into client_details '$sex', '$name', '$address', '$dob'");
?>

RE: Connecting to a online SQL dabatase by LifelesS on 04-03-2007 at 08:40 PM

Thank you, you solved my problem. Because I didn't know how to make JScript and PHP work together, I was already starting to make a DLL in VB for acessing it, but I'll try it that way.

Again, many thanks:)


RE: Connecting to a online SQL dabatase by ShawnZ on 04-03-2007 at 09:36 PM

DON'T LISTEN TO ABSORBATION

if you were to use a php script like that, anyone could just go in and add whatever entries they want -- plus, they could change that query any way they wanted since it isn't properly escaped. i highly recommend you use some sort of mysql client dll.


RE: Connecting to a online SQL dabatase by -dt- on 04-04-2007 at 02:36 AM

Hello

Look at this post http://shoutbox.menthix.net/showthread.php?tid=62...d=696175#pid696175

that connects to a Access database, to connect a mysql one you need to do two things.

to enable the use of mysql you will have to download the odbc connector http://dev.mysql.com/downloads/connector/odbc/3.51.html

then change the db.Open line to

code:
db.Open("DRIVER={MySQL ODBC 3.51 Driver};SERVER=SERVERADDRESS;UID=USERNAME;PWD=PASSWORD;DATABASE=DATABASE;");


with that change you should be able to use the code in the linked post to connect to mysql : >


(Im assuming you meant Mysql, but you can apply this post to any database, you just need to the correct connector and connection string)