Help setting up a web server using CGI & Mysql

Southy

New Member
Hi all,
I have a linux machine running apache for a personal website I run from home. I created a CGI application using C/C++ to run on this website, it does a few various things like having users login, etc... As of now, the way I programmed it, the cgi app uses text files to store the data for the website and now that I have learned more, I am wanting to try and use MySql instead. Only problem is, I dont know how to get my CGI application to talk to MySql, so that I can store the data in it. I am fairly new to MySql and have only recently got some experience using it. I have it installed on the linux machine and my win Xp machine as well, mostly just to test things out. I do not know PHP and do not plan on using it as I want to continue my web apps in C/C++. Can anyone help me or give me some references on where I can learn to setup this up to work? Muchly appreciated.
 
here is a script to connect to a mysql database using CGI/Perl:
PHP:
 #!/usr/bin/perl -T
print "ContentType: text/plain\n\n";

use DBI;

# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=your_databasename;host=mysql.secureserver.net";
$dbh = DBI->connect($dsn,"your_dbusername","your_dbpassword");

# Select the data and display to the browser

my $sth = $dbh->prepare("SELECT * FROM customers");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
}

$sth->finish();

# Disconnect from the database.

$dbh->disconnect();
# taken from http://help.godaddy.com/article.php?article_id=254&topic_id=67&
There is probably some tutorials that explain how to do it more easily, but that is what I found from a quick google search. Alternatively you could possibly create a php script that reads/writes to the database, and returns the values to you scripts, but that would be much harder, and require PHP knowledge
 
Back
Top