Sponsored Content
Top Forums Programming derefencing issue with perl and mysql Post 302309426 by s_becker on Tuesday 21st of April 2009 10:04:55 PM
Old 04-21-2009
Yes, the SQL_* stuff was superflous. Also, I was using a reserved word as a column name and had autocommit = 0.

Here is the working code:

Code:
#!/usr/bin/perl 

#use DBI;
use DBD::mysql;
use DBI qw(:sql_types);

$hostname = "localhost";
$database = "c2";
$username = "collect";
$password = "password";

$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password", {
                          RaiseError => 1,
                          AutoCommit => 1
                        }
                      ) || die "Database connection not made: $DBI::errstr";

$sth = $dbh->prepare("SELECT server_id FROM server WHERE server_name =?"); 
$ins = $dbh->prepare("INSERT INTO server_details (server_id, apt_source, cleaner_conf, crons, date, df, dmidecode, ethtool, fstab, groups, hosts, hosts_allow, hosts_deny, ifconfig, j2_serverconf, last, lsmod, lspci, mdstat, mount_nfs, netstat, network, proc_scsi, pw, raidtab, rpm_list, sudoers, sysctl, tr114, uname) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");


$dir = "/usr/local/c2/serverfiles";
opendir(sf, $dir) or die "can't open $dir: $!";
while (defined($serv_dir = readdir(sf))) {
        @data_load = "";
        next if $serv_dir =~ /^\.\.?$/; # skip . and ..
        $sth->execute($serv_dir) or die $sth->errstr;
        $sid = $sth->fetchrow_array;
                #logic to make new server entries if sid = null
        print "$serv_dir has a server id of: $sid\n"; 
                @xml = glob("$dir/$serv_dir/*.xml");
                @data_load[0] = "$sid";
                $inc = 1;
                foreach $xml_file (@xml) {
                         open(XMLFILE, "$xml_file" ) or die "can't open $xml_file: $!"; 
                        while(<XMLFILE>) {
            @data_load[$inc] .= $_;
            }
            $inc++;


$ins->bind_param(1,$data_load[0]); # server_id foreign key
$ins->bind_param(2,$data_load[1]); #apt_source
$ins->bind_param(3,$$data_load[2]); # cleaner_conf
$ins->bind_param(4,$data_load[3]); # crons
$ins->bind_param(5,$data_load[4]); # date
$ins->bind_param(6,$data_load[5]); # df
$ins->bind_param(7,$data_load[6]); # dmidecode
$ins->bind_param(8,$data_load[7]); # ethtool
$ins->bind_param(9,$data_load[8]); # fstab
$ins->bind_param(10,$data_load[9]); # group
$ins->bind_param(11,$data_load[10]); # hosts_allow
$ins->bind_param(12,$data_load[11]); # hosts_deny
$ins->bind_param(13,$data_load[12]); # hosts
$ins->bind_param(14,$data_load[13]); # ifconfig
$ins->bind_param(15,$data_load[14]); # j2_serverconf
$ins->bind_param(16,$data_load[15]); # last
$ins->bind_param(17,$data_load[16]); # lsmod
$ins->bind_param(18,$data_load[17]); # lspci
$ins->bind_param(19,$data_load[18]); # mdstat
$ins->bind_param(20,$data_load[19]); # mount_nfs
$ins->bind_param(21,$data_load[20]); # netstat
$ins->bind_param(22,$data_load[21]); # network
$ins->bind_param(23,$data_load[22]); # proc_scsi
$ins->bind_param(24,$data_load[23]); # pw
$ins->bind_param(25,$data_load[24]); # raidtab
$ins->bind_param(26,$data_load[25]); # rpm_list
$ins->bind_param(27,$data_load[26]); # sudoers
$ins->bind_param(28,$data_load[27]); # sysctl
$ins->bind_param(29,$data_load[28]); # tr114
$ins->bind_param(30,$data_load[29]); # uname
#$ins->bind_param(31,$data_load[30],SQL_DATETIME); # timestamp
$ins->execute() || die "FAIL: $DBI::errstr";
}
closedir(sf);

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mysql issue

I have a lot of files getting this on a new install of phpmysql 4.3.4 any ideas what would be causing this... Fatal error: Call to undefined function: mysql_connect() in /home/httpd/vhosts/ucandevelopments.com/httpdocs/includes/functions/database.php on line 19 (4 Replies)
Discussion started by: Blackrose
4 Replies

2. UNIX for Dummies Questions & Answers

PHP-MySQL: POST issue

I am moving from a shared hosting environment to a dedicated box. The migration also involves a mySQL database managed using a web-based PHP interface. I can read the contents of the db (connection is good) but when I try to administer, the form variables aren't going from step 1 (add) to step 2... (0 Replies)
Discussion started by: adrious
0 Replies

3. UNIX and Linux Applications

mysql query browser issue

Hi, I'm new to mysql, I've installed MYSQL on our unix server and started MYSQL on this server. I've now downloaded MYSQL Query Browser, when I try to connect to MYSQL server, I get the following error "could not connect to the specified instance" - MySQL Error Number 1130. From the... (3 Replies)
Discussion started by: venhart
3 Replies

4. Shell Programming and Scripting

perl+CGI+mysql !!!!!!!

hi expert, I am totally new to perl CGI coding. And stop by below issue: 1> i have a script names conn.pl, which can connect to mysql and get the information of table user(id,name) 2> i copied above code into one CGI web page named user.cgi 3> when i view user.cgi in web browser, it toldme... (3 Replies)
Discussion started by: summer_cherry
3 Replies

5. Web Development

Strange Mysql issue

Hi all, I recently changed the name of my hostname from 'abc123' to 'abc456' (as an example). I then added a user in my mysql database with the new host and removed references to the old users and hostname. The strange thing is though, a process using the database still uses the old... (1 Reply)
Discussion started by: muay_tb
1 Replies

6. Linux

mysql server start issue

Hi, I have installed mysql in linux box as mysql-5.0.77-4.el5_6.6.. I would like to start the server. But there is no mysql file in this location /etc/init.d/ Please advice how to start the server now !! Thnaks, Mani (5 Replies)
Discussion started by: Mani_apr08
5 Replies

7. Programming

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: perl -c Brapa0101-db.pl Brapa0101-db.pl syntax OKHowever, whenever I run it, an error message was tossed out: DBD::mysql::st execute... (7 Replies)
Discussion started by: yifangt
7 Replies

8. Programming

LEFT JOIN issue in Mysql

I have a data table as follows: mysql> select * from validations where source = "a03"; +------------+-------+--------+ | date | price | source | +------------+-------+--------+ | 2001-01-03 | 80 | a03 | | 2001-01-04 | 82 | a03 | | 2001-01-05 | 84 | a03 | | 2001-01-06... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

syntax issue with quotes in mysql command for a bash script

i'm trying to write a bash script that executes a mysql statement mysql -sN -e INSERT INTO "$database"."$tableprefix"users (var1, var2,var3) VALUES (123, '1','') i don't know where to put the quotes it doesnt work with this one: ` it seems i can only put double quotes around the... (0 Replies)
Discussion started by: vanessafan99
0 Replies

10. Shell Programming and Scripting

syntax issue mysql in bash script

I'm running mysql in a bash script mysql <<EOF query EOF one query is like this: UPDATE $dbname.$prefix"config" SET value = $var WHERE "$prefix"config.name = 'table colname'; with variable but it's giving an error i'm not sure what to put for "$prefix"config.name the table... (3 Replies)
Discussion started by: vanessafan99
3 Replies
DBIx::SearchBuilder::Handle::mysql(3pm) 		User Contributed Perl Documentation		   DBIx::SearchBuilder::Handle::mysql(3pm)

NAME
DBIx::SearchBuilder::Handle::mysql - A mysql specific Handle object SYNOPSIS
DESCRIPTION
This module provides a subclass of DBIx::SearchBuilder::Handle that compensates for some of the idiosyncrasies of MySQL. METHODS
Insert Takes a table name as the first argument and assumes that the rest of the arguments are an array of key-value pairs to be inserted. If the insert succeeds, returns the id of the insert, otherwise, returns a Class::ReturnValue object with the error reported. SimpleUpdateFromSelect Customization of "SimpleUpdateFromSelect" in DBIx::SearchBuilder::Handle. Mysql doesn't support update with subqueries when those fetch data from the table that is updated. DatabaseVersion Returns the mysql version, trimming off any -foo identifier CaseSensitive Returns undef, since mysql's searches are not case sensitive by default SimpleDateTimeFunctions Returns hash reference with specific date time functions of this database for "DateTimeFunction" in DBIx::SearchBuilder::Handle. ConvertTimezoneFunction Custom implementation of "ConvertTimezoneFunction" in DBIx::SearchBuilder::Handle. Use the following query to get list of timezones: SELECT Name FROM mysql.time_zone_name; Read docs about keeping timezone data up to date: http://dev.mysql.com/doc/refman/5.5/en/time-zone-upgrades.html AUTHOR
Jesse Vincent, jesse@fsck.com SEE ALSO
DBIx::SearchBuilder, DBIx::SearchBuilder::Handle perl v5.14.2 2011-09-21 DBIx::SearchBuilder::Handle::mysql(3pm)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy