in reply to DBI connect problems

If I understand what you are asking:

If you want a more significant answer you should post at least an abstract of your code.

Careful with that hash Eugene.

Replies are listed 'Best First'.
Re^2: DBI connect problems
by Anonymous Monk on Jun 12, 2008 at 15:28 UTC
    Here is the code:Its working well on the windows.I am trying to run this on linux.
    #!/usr/local/bin/perl use DBI; &MakeTable; &InsertValues; sub MakeTable() { use DBI; #print "enter username\n"; $dbh = DBI->connect("dbi:mysql:namesdb", 'some' , 'someother',{ Auto +Commit => 1, RaiseError => 1}) or die "connection error:$DBI::errstr\ +n"; $dbh-> do( "create table if not exists names ( #stuff );" ); $dbh-> disconnect; }#sub ends here; sub InsertValues() { $tablename="names"; $infile = '/path/names.dmp'; # $field= "\t|\t"; # field ending syntax from file; $lines="\t|\n";#lines ending syntax from file; $command = qq ~load data infile '$infile' ignore into table $tablen +ame FIELDS terminated by '$field' LINES terminated by '$lines';~; $dbh = DBI->connect("dbi:mysql:namesdb", 'some' , 'someother',{ Auto +Commit => 1, RaiseError => 1}) or die "connection error:$DBI::errstr\ +n"; $dbh->do($command); $dbh-> disconnect; }

    Jun 14, 2008 at 04:22 UTC McDarren Added code tags, removed excessive whitespace

      Please, next time use <code> tags to embed code in your posts, I had to reformat all the code to be able to read it.

      I see that you use DBI inside the first sub, and this is unnecessary for you have already used it before.

      I see also that you don't use strictures and this is bad.

      use strict; use warnings;

      are your friends.

      I don't know why the second call returns an error, as I said before best practice is to connect to db once at the beginning and disconnect at the end of the script. If you want to connect/disconnect in every sub, try adding strictures, add the global part of your code (the calls to the subs), execute it and see which error(s) results

      After this, post again the "complete" code (the minimal code that can be executed giving the error) AND the resulting error (sorry, I can't test it because I don't have mysql installed on my machine)

      Careful with that hash Eugene.

        hi psini, I figured out that admin has not granted me privs to use certain types of commands. We are checking on that. Ya...I got to use -w and strict.