MySQL Forums
Forum List  »  General

Re: IF THEN ELSE, not working, but why?
Posted by: Lyle Hopkins
Date: July 29, 2008 04:52PM

In the end I had to use a little Perl:-

use DBI;
use Carp;

my $dbh = DBI->connect( 'DBI:mysql:database=sample;host=localhost;', user, pass )
|| croak("Cannot connect to database: $DBI::errstr\n");

$dbh->{AutoCommit} = 0;
if ( $dbh->{AutoCommit} ) { croak( "Cant turn off autocommit" ); }

$dbh->do( 'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ' ) || croak("database err: $DBI::errstr\n");
$dbh->do( 'BEGIN' ) || croak("database err: $DBI::errstr\n");
#$dbh->do( "SELECT \@ip := `ip` FROM `list_ip` WHERE `ip`=''" ) || croak("database err: $DBI::errstr\n");
my $sth = $dbh->prepare( "SELECT `ip` FROM `list_ip` WHERE `ip`=''" ) || croak("database err: $DBI::errstr\n");
$sth->execute() || croak("database err: $DBI::errstr\n");
my $hash_ref = $sth->fetchrow_hashref();
print $hash_ref;
unless ($hash_ref) {
$dbh->do( "INSERT INTO `list_ip` ( `ip` ) VALUES( '' )" ) || croak("database err: $DBI::errstr\n");
$dbh->do( 'COMMIT' ) || croak("database err: $DBI::errstr\n");


print "done";

Options: ReplyQuote

Written By
Re: IF THEN ELSE, not working, but why?
July 29, 2008 04:52PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.