How to connect to an online database

Community Forums/General Help/How to connect to an online database

Blitzplotter(Posted 2010) [#1]
This morning I managed to create three tables on the internet within some of my webspace using myPHP. The idead is that I have a members table with a few fields, an events table with a few fields and a table that will use elements of both - a MemberEvent table that will contain a score field. I've a couple of questions:

1. How to you 'connect' an internet page to a online database - do you embed the 'connect to online database as step one of the code within a pages button, then make step 2 pose the query, then step 3 - display the results of the query & finally step 4 - disconnect from the database ?

2. Is it possible to embed a SQL query within a button CSS style, then have the results of the database query presented within the internet page ?

3. Do you have to 'disconnect' from the database after each button press (which will contain a query)

I am considering amending the online database with a VB Express front end (its what I'm using with the OU at the moment).

Thanks in advance for any guidance - so far I've found this:-

http://dev.mysql.com/tech-resources/articles/ddws/


xlsior(Posted 2010) [#2]
1. Most sites use an include at the top of the page that takes care of establishing a connection to the SQL database. The include should reside in a seperate folder that is readable by the webserver, but not the public at large. (the reason for that: if the PHP parser on the server breaks for whatever reason, you do NOT want the end user to be able to see your SQL connection server / user / password information in plain view!)
You individual pages then could just have an include "dbconnect.php" kind of statement, and automagically establish the DB connection for you.

2) The SQL stuff gets processed by the server, and the *results* of that query gets passed on to the end-users browser. Unless you are using forms that re-query the server when the user clicks on something, the answer is going to be "no".

3) You should, or the SQL server may stop returning information if there are to many active sessions open... It may look like a denial-of-service attack otherwise, when you have hundreds or thousands of sessions open after a while.


GfK(Posted 2010) [#3]
3) You should, or the SQL server may stop returning information if there are to many active sessions open... It may look like a denial-of-service attack otherwise, when you have hundreds or thousands of sessions open after a while
...plus if you start leaving persistent connections all over the place on shared hosting, your provider is going to get a bit arsey with you over it.

Other than that, I normally go here when I need a quick solution/help with any web dev stuff.


Blitzplotter(Posted 2010) [#4]
@xlsior, thanks for the feedback.

@GfK, thanks for the link. Must admit I was getting a bit like a rabbit in the headlights wondering how to 'connect' tables the way you can within Access and the like.