insert into mysql with pattern matching

From: Hendra Kusnandar (hendrakusnandar_at_yahoo.com)
Date: 03/13/04

  • Next message: Veera Prasad: "bad file descriptor .."
    Date: Sat, 13 Mar 2004 07:23:10 -0800 (PST)
    To: dbi-users@perl.org
    
    

    hello all,
     
    #!/usr/bin/perl
    use DBI;
    sub insert {
     my ($insert_sql,$sth);
     my $nik=12345678; # 8 digit
     my $password=12345678; # 8 digit
     my $scode=2; # 1 digit

    #configuration database
      $database = "user";
      $dbuser = "hendra";
      $dbpasswd = "hendra123";
      $dbhost = "localhost";
      $dsn = "DBI:mysql:database=$database;host=$dbhost";
      $dbh = DBI->connect($dsn,$dbuser,$dbpasswd) || die $DBI::errstr;
      $insert_sql = qq {insert into user (nik,password,scode) values (?,?,?)};
      $sth = $dbh->prepare($insert_sql) || die "prepare: $insert_sql: $DBI::errstr";
      $sth->execute($nik,$password,$scode) || die "Unable to execute query: $dbh->errstr\n";
     
      $sth->finish;
      $dbh->disconnect;
    }
    print "INPUT : ";
    while ($input=<>) { # Read the user input
      # format: nik[space]password[space]scode -> use pattern matching
      if ($input =~/12345678 12345678 2/){
            insert();
      } else {
            print "Cannot Insert";
      }#end if
      print "INPUT : ";
    }#end while
    ==================================
    that's scripts work and data can insert into mysql.
     
    but i can't insert any data to mysql if i change the variabel on top with this :
     
     my $nik = @_; # 8 digit
     my $password = @_; # 8 digit
     my $scode = @_; # 1 digit
     
    and also i change :
     
      # format: nik[space]password[space]scode -> use pattern matching
      if ($input =~/(\d{8})(\s{1})(\d{8})(\s{1})(\d{1})/){
      .................
     
    if i execute the scripts with another input, data will insert into mysql what i type in shell but data incorrect and on tabel the value is 0 for each fields.

    the question is how to insert data into mysql with another input from shell with pattern matching.

    regards,

    hendra kusnandar

    Do you Yahoo!?
    Yahoo! Mail - More reliable, more storage, less spam


  • Next message: Veera Prasad: "bad file descriptor .."

    Relevant Pages

    • Re: mySQL and SUSE 9.0 problem
      ... I installedall the packages ... > bin/mysql.When I tried to start the server I got ... I also ran into a lot of trouble getting MySQL to just start on my Suse 9.0 ... shell> useradd -g mysql mysql ...
      (alt.os.linux.suse)
    • Re: restrict port forwarding on the server side
      ... > using ssh port forwarding/tunneling since I don't want to open the MySQL ... I created a user for the customer which gets a shell script as shell that ... The user still can use sftp and scp ...
      (SSH)
    • Re: Problem installing Mysql from Zeniz.com on 5.0.7
      ... The FSU-threads needs the system to have all the latest patches. ... FSU-threads and MySQL are very tempramental to system changes and the way ... shell> useradd -g mysql mysql ... I usuall do a make install to get the FSU-threads setup properly. ...
      (comp.unix.sco.misc)
    • Problem installing Mysql from Zeniz.com on 5.0.7
      ... shell> useradd -g mysql mysql ... I found no instructions in the FSU-theads-3.14 tarball so I ... Steve Fabac ...
      (comp.unix.sco.misc)
    • Re: Unix Shell script and MySql
      ... > database. ... MySQL comes with 'mysql' command line client program. ... have direct shell access to the query result, ... It's part of my BashDiff collection. ...
      (comp.unix.shell)