Sponsored Content
Top Forums Programming Help with mySQL database by perl script Post 302559646 by yifangt on Tuesday 27th of September 2011 07:28:22 PM
Old 09-27-2011
Help with mySQL database by perl script

Hello;

I was trying to set up a mysql database using following script, but never went through. The code seems fine without any syntax error as I tested it:
Code:
perl -c Brapa0101-db.pl
Brapa0101-db.pl syntax OK

However, whenever I run it, an error message was tossed out:
Code:
DBD::mysql::st execute failed: called with 9 bind variables when 0  are needed at Brapa0101-db.pl.bk line 45, <FILE> line  41174.

Could any expert help me through this problem? Thanks a lot!
Here is my code:
Code:
#!/usr/bin/perl -w

use strict;
use DBI;

# # # # # # # # # # # # # # # #  # # # # # # # # # # # # # # 
#The database "Brapa0101_db" has been created with mysql
#mysql> CREATE database Brapa0101_db;
# # # # # # # # # # # # # # # #  # # # # # # # # # # # # # # 

my $DataBaseName="Brapa0101_db";
my $DataBaseHost="localhost";
my $MySQLUser="myql_account";
my $MySQLUserPass="passwrdxyzt";
my $dsn="DBI:mysql";
my $Table="table01" ;
    

my $dbh = DBI->connect("$dsn:$DataBaseName:$DataBaseHost", $MySQLUser, $MySQLUserPass) 
            or die "Cannot connect: " . $DBI::errstr;
   my $sql = qq/INSERT INTO $Table 
                      (run, geneid,            seqtype,     scaffold,  seqstart, seqend, seqstrand,  seqlength, cdsseq)
              VALUES( int, char(20) primary key, char(20), char(100), int,   int, char(10), int,    text(40000))
            /;
##############Example rows of the file /path/to/MySQL_Study/Brapa1.1-database/Brassica_rapa.20100830.cds.tab5"
#    Run    Gene    mRNA    Scaffold    Start    End    Strand    Length    Sequence
#    1    Bra000001    [mRNA]    locus=Scaffold000001    3252        5836        +    2584    ATGGGGAAGATCTTGAAAACTAAGTCTT
#    2    Bra000002    [mRNA]    locus=Scaffold000001    6640        9120        -    2480    ATGGAGGAAGTAAGGAAGATGGGTTGTAT
#    3    Bra000003    [mRNA]    locus=Scaffold000001    21211    22012    +    801    ATGAGCTCTGTTTGTGGTAAGCTGGATTT
#    4    Bra000004    [mRNA]    locus=Scaffold000001    25599    25973    +    374    ATGATTCGCCGTCTATTCTCGTCTCTGACT.
#    5    Bra000005    [mRNA]    locus=Scaffold000001    26822    28864    -    2042    ATGGCGGCAGCTAGACGATT..
#    6    Bra000006    [mRNA]    locus=Scaffold000001    29480    29791    -    311    ATGTC...............
my $sth = $dbh->prepare($sql);

my $file_name="/path/to/MySQL_Study/Brapa1.1-database/Brassica_rapa.20100830.cds.tab5";

open(FILE, "<$file_name") or die("Cannot open the file named $file_name to read!");
     
foreach my $line (<FILE>) {
    # next if $_=~ m/Run\t/;                #This $_ has caused many headaches on me, 
    
     next if $line=~ m/Run\t/;                #This is the right syntax 
     chomp $line;
  my @fields = split(/\t/, $line);
    $sth->execute(@fields);
}

while (my $row = $sql->fetchrow_arrayref) {
        print join("\t", @$row), "\n";
    }
$dbh->disconnect;

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connecting MySql throug Perl Script ?

Dear Friends, I am tryin to connect to the myql through perl scrip. I have already installed mysql and DBI modules to my Perl. There versions are as follows, DBD-mysql MySQL driver for the Perl5 Database DBI Database independent interface for It gives... (4 Replies)
Discussion started by: maheshsri
4 Replies

2. Shell Programming and Scripting

shell script to insert data from gps.txt to mysql database

Hi, I have gps receiver, by using gpsd data i can read gps log data to my database(my sql). Steps: 1. telenet localhost 2947 > gps.txt (press enter) 2. r (press enter) //then i will get the data like below in gps.txt file Trying 127.0.0.1... Connected to localhost.... (1 Reply)
Discussion started by: gudivada213
1 Replies

3. Shell Programming and Scripting

Automating A Perl Script over a database

Dear Scripting Gods I've never done shell scripting before and have only recently got to grips with Perl, so apologies for my naivity. I've written a perl program which takes in two files as arguments (these are text documents which take in the information I need) The perl program spits out a... (1 Reply)
Discussion started by: fraizerangus
1 Replies

4. Shell Programming and Scripting

Create mysql database with bash script - confused

Hi, i have the following: db="create database xxx;GRANT ALL PRIVILEGES ON xxx.* TO user@localhost IDENTIFIED BY 'password';FLUSH PRIVILEGES;quit;" mysql -u root -p$mysql_pass -e "$db" I don't understand why this is failing, it works fine when run from cmd but when is run in a bash script,... (1 Reply)
Discussion started by: ktm
1 Replies

5. Shell Programming and Scripting

[Perl] script -database

Welcome. I am writing a perl script. I have to design a database consisting of a single table (any subject) saved in a text file. (I make it vi command name and I am giving permission chmod u + x?) The table should contain at least four columns, including a column containing the ID (serial number )... (4 Replies)
Discussion started by: qwerty007
4 Replies

6. Shell Programming and Scripting

Help with perl mysql backup script

Hi, im trying to make a script that backups mysql databases but apparently I am having trouble with the variables, or simply something I am missing. Would appreciate any help, here is the script #!/usr/bin/perl -w use strict; require File::Spec; #VARIABLES my $databasename =... (4 Replies)
Discussion started by: Fireline
4 Replies

7. Shell Programming and Scripting

Perl script database date convertion

Need assistance Below script get the output correctly I want to convert the date format .Below is the output . Any idea ? #!/usr/bin/perl -w use DBI; # Get a database handle by connecting to the database my $db = DBI->connect(... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

8. Shell Programming and Scripting

Need help on Insert data to phpMyAdmin mySQL database from Shell Script

Sorry to disturb you, I would like to seek help on inserting data whenever the switch is on or off to my phpMyAdmin mySQL database from my Shell Script. I'm using Raspberry PI as my hardware and I have follow this LINK: instructables.com/id/Web-Control-of-Raspberry-Pi-GPIO/?ALLSTEPS to create my... (4 Replies)
Discussion started by: aoiregion
4 Replies
CGI::Session::Driver::mysql(3)				User Contributed Perl Documentation			    CGI::Session::Driver::mysql(3)

NAME
CGI::Session::Driver::mysql - CGI::Session driver for MySQL database SYNOPSIS
$s = new CGI::Session( 'driver:mysql', $sid); $s = new CGI::Session( 'driver:mysql', $sid, { DataSource => 'dbi:mysql:test', User => 'sherzodr', Password => 'hello' }); $s = new CGI::Session( 'driver:mysql', $sid, { Handle => $dbh } ); DESCRIPTION
mysql stores session records in a MySQL table. For details see CGI::Session::Driver::DBI, its parent class. It's especially important for the MySQL driver that the session ID column be defined as a primary key, or at least "unique", like this: CREATE TABLE sessions ( id CHAR(32) NOT NULL PRIMARY KEY, a_session TEXT NOT NULL ); To use different column names, change the 'create table' statement, and then simply do this: $s = new CGI::Session('driver:mysql', undef, { TableName=>'session', IdColName=>'my_id', DataColName=>'my_data', DataSource=>'dbi:mysql:project', }); or $s = new CGI::Session('driver:mysql', undef, { TableName=>'session', IdColName=>'my_id', DataColName=>'my_data', Handle=>$dbh, }); DRIVER ARGUMENTS mysql driver supports all the arguments documented in CGI::Session::Driver::DBI. In addition, DataSource argument can optionally leave leading "dbi:mysql:" string out: $s = new CGI::Session( 'driver:mysql', $sid, {DataSource=>'shopping_cart'}); # is the same as: $s = new CGI::Session( 'driver:mysql', $sid, {DataSource=>'dbi:mysql:shopping_cart'}); BACKWARDS COMPATIBILITY As of V 4.30, the global variable $CGI::Session::MySQL::TABLE_NAME cannot be used to set the session table's name. This is due to changes in CGI::Session::Driver's new() method, which now allows the table's name to be changed (as well as allowing both the 'id' column name and the 'a_session' column name to be changed). See the documentation for CGI::Session::Driver::DBI for details. In particular, the new syntax for "new()" applies to all database drivers, whereas the old - and bad - global variable method only applied to MySQL. Alternately, call $session -> table_name('new_name') just after creating the session object if you wish to change the session table's name. LICENSING
For support and licensing see CGI::Session. perl v5.16.3 2008-07-16 CGI::Session::Driver::mysql(3)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy