in reply to MySQL avoid multiple connect request
poj#!/usr/bin/perl use strict; use warnings; use DBI; my $db = 'xxxx'; my $table = 'xxxx'; my $dbh = dbh(); # connect # create database $dbh->do('CREATE DATABASE IF NOT EXISTS '.$db) or die "Could not create database $db : ". $dbh->errstr; # create table $dbh->do("USE $db"); $dbh->do("CREATE TABLE IF NOT EXISTS $table ( id int(11) NOT NULL AUTO_INCREMENT, UnixTime int(11) NOT NULL, losses int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1"); # insert data my $range = 50; my $minimum = 100; my $random_number = int(rand($range)) + $minimum; my $time = time(); $dbh->do("INSERT IGNORE INTO $table (UnixTime,losses) VALUES (?,?)", undef, $time,$random_number); print "added $time $random_number to $db table $table\n"; sub dbh { my $dsn = "DBI:mysql:database=;host=localhost"; my $dbh = DBI->connect($dsn, 'user', 'pwd', {RaiseError => 1, PrintError => 1}) or die (Error connecting " $DBI::errstr"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MySQL avoid multiple connect request
by thanos1983 (Parson) on May 23, 2014 at 21:08 UTC | |
by thomas895 (Deacon) on May 24, 2014 at 01:03 UTC | |
by boftx (Deacon) on May 24, 2014 at 01:14 UTC | |
by thanos1983 (Parson) on May 24, 2014 at 18:22 UTC |