Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mySQL code

Status
Not open for further replies.
Feb 16, 2003
87
GB
Hello!

I'm looking for some basic code that will let me add a record to a mySQL table hosted on the same server.

Nothing fancy - any ideas anyone?

Simon
 
I'm still stuck with this problem folks if anyone can help - I've got some PHP code but that won't work in Perl!!!!

Simon
 
Geting stuff out.
This will select the entire row that a field in "columname" is equal to $variable. The DBI will substitute the ? for $variable for you.

use DBI;
con();#<--holds connect info

$sth=$dbh->prepare (qq{
SELECT *
FROM `tablename`
WHERE `columname`=?
} );
$sth->execute ($varible);

my $referencehash= $sth->fetchrow_hashref;

$sth->finish;
dis();

Use selected data:
$data_in_a_column = $referencehash->{columname};

Putting stuff in:

con();
#insert new row
$sth=$dbh->prepare (qq{
INSERT INTO `tablename`
SET `column` = ?, `column2` = ?
} );
$sth->execute ($variable, $variable2);

$sth->finish;
dis();

#updating an existing row
con();

$sth=$dbh->prepare (qq{
UPDATE `tablename`
SET `column` = ?, `column2` = ?
WHERE `somecolumnname`=?
} );
$sth->execute ($variable, $variable2);

$sth->finish;
dis();

haunter@battlestrata.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top