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"); }
In reply to Re: MySQL avoid multiple connect request
by poj
in thread MySQL avoid multiple connect request
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |