473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DBI queries with same results (mysql)

Hi all,

I created a script that query a Database in mysql. Everything goes
right except the fact that the results for various queries are the
same. I use $sth->finish() and $dbh->disconnect() correctly.

I don't know what is going wrong because when i use another script
to query my database (written in php), the results of the queries are
different (they are updated).

How can i write an perl script that give me the right results? I've
read a lot of docs about DBI, and all of them tell me the same thing.

Here's a piece of my code:

---
$drh = DBI->install_driver('mysql');

#$dsn = "DBI:$driver:database=$database";
$dsn = "DBI:$driver:dbname=$database";
$dbh = DBI->connect($dsn, $user, $password) or die "Nao consegui
conectar ao banco de dados, motivo: $DBI::errstr\n ";

#$sth = $dbh->prepare("SELECT count(ip_dst),ip_src,ip_dst FROM
acid_event GROUP BY ip_dst");
my $sql = qq{SELECT count(ip_dst),ip_src,ip_dst FROM acid_event GROUP
BY ip_dst};
$sth = $dbh->prepare($sql);

if (!$sth) {
die "Erro na query:" . $dbh->errstr . "\n";
}

if (!$sth->execute()) {
die "Erro na execucao da query:" . $sth->errstr . "\n";
}
my $names = $sth->{'NAME'};
my $numFields = $sth->{'NUM_OF_FIELDS'};

# Imprime os dados da tabela
my $count0 = 0;
my $count2 = 0;
my @contador = ();
my @ip_destino = ();

while (my $ref = $sth->fetchrow_arrayref) {
for (my $i = 0; $i < $numFields; $i++) {
if ($i == 0) {
$contador[$count0] = $$ref[0];
}
if ($i == 2) {
$ip_destino[$count2] = $$ref[2];
}
$contadorh{$$ref[0]} = $contador[$count0];
$ip_dst{$$ref[0]} = $$ref[2];
$count0++;
$count2++;
}#for
}#while

# Release the statement handle resources
$sth->finish;

# Disconnect from the database
$dbh->disconnect;
---

Any help is very valuable!!

Many thanks!
Jul 19 '05 #1
1 2612
If you run your script twice, and get the same results, then it
doesn't sound as though it has anything to do with releasing
resources.

However, I noticed something suspicious in your query. I am not sure
this accounts for your problem, but I believe it is wrong anyway. In
the statement
my $sql = qq{SELECT count(ip_dst),ip_src,ip_dst FROM acid_event GROUP
BY ip_dst};


Your select list includes ip_src and ip_dst, but only groups by
ip_dst. I am surprised that this even runs at all, since the database
engine has no way of knowing how ip_src and ip_dst relate to one
another.

Otherwise, I don't see anything wrong, either.

- Jerry Oberle
perl -e 'printf "mailto%c%s%c%s%cchase%ccom%c", 58, "Gerard", 46,
"Oberle", 64, 46, 10;'
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
http://www.php.net/array_filter I went there at first for my information on filtering mySQL query results using PHP, to no avail. This is more of a Vignette construct (my native environment)...
7
by: frizzle | last post by:
Hi, I know this might sound strange but i think(/hope) it's quite simple: I'm running 2 queries in a mysql DB, first one returns 20 results. Now how can i echo results from the second query...
1
by: Thomas Bartkus | last post by:
Can anyone point to documentation, or pass along some insight on how MySQL handles dropped connections and abandoned queries? How does MySQL cope with people/processes that log on and then...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
10
by: m.k.ball | last post by:
I have three tables, containing information about three people and the cars that they own. One table lists people, one lists cars, and one uses the id's from the other two to compile a list of...
1
by: zek2005 | last post by:
Hi!!!! I´m stuck with a problem I have to make a table with the information of three different queries. The table has 4 columns x n rows. The first and second columns must be filled with the...
4
by: Got2Go | last post by:
Hello Group, I have a table that has millions of records in it. About 100 records are added every 5 minutes (one per OIDID) (the sample provided below has data for 2 OIDIDs (99 and 100) And I...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
8
by: Daz | last post by:
Hi everyone. I was faced with the choice of whether my problem is indeed a PHP problem or a MySQL. I have decided it's a PHP problem as I don't experience the same problem when I execute the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.