Re: IF THEN ELSE, not working, but why?
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`='1.1.1.1'" ) || croak("database err: $DBI::errstr\n");
my $sth = $dbh->prepare( "SELECT `ip` FROM `list_ip` WHERE `ip`='1.1.1.1'" ) || croak("database err: $DBI::errstr\n");
$sth->execute() || croak("database err: $DBI::errstr\n");
my $hash_ref = $sth->fetchrow_hashref();
$sth->finish();
print $hash_ref;
unless ($hash_ref) {
$dbh->do( "INSERT INTO `list_ip` ( `ip` ) VALUES( '1.1.1.1' )" ) || croak("database err: $DBI::errstr\n");
}#unless
$dbh->do( 'COMMIT' ) || croak("database err: $DBI::errstr\n");
$dbh->disconnect;
print "done";
Subject
Written By
Posted
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.