I wanted to test the bandwidth for my website every 15 minutes (to verify my
ISP was getting me 1.5 like they say)and was wondering if there are any
modules that make the job easier.  Any help would be appreciated.
Currently, there are tools out there that do what I want but I wanted to
write my own and was wondering if anyone had any ideas.
tia

-----Original Message-----
From: Gabriel Cooper [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 19, 2003 9:01 AM
To: Voodoo Raja
Cc: [EMAIL PROTECTED]
Subject: Re: Display realtime data As it changes in the databse - TK



Ramprasad A Padmanabhan wrote:

> Voodoo Raja wrote:
>
>> Sorry for not posting it in the first place.
>>
>> Will this sub.. chew memory if I run it a number of times.. or does
>> it overwrite it.
>>
>> sub read {
>> print "\nreading data";
>> $db = DBI->connect("DBI:mysql:$dbase:$hostname", $username, $password);
>
as Ramprasad said, you should pass in your db connection if you use it
in more than one function...

>>
>> $query = $db->prepare("SELECT * FROM cash where f1 = '1002'");
>
Generally speaking, if you're selecting " * " then you're doing
something wrong. You should only select exactly what you want from a
database rather than "just give me it all and I'll figure it out later".
Especially because--judging from the loop below--you don't appear to use
anything in the db except the first field, but also because this method
doesn't take into account changing database structure. Ramprasad
suggested "select max($field1) from cash where $x = $y " but keep in
mind you should do this using placeholders where any user input is
involved to protect yourself from SQL injection attacks. =]

>>
>> $query->execute;
>> $numrows = $query->rows;
>> while (@array = $query->fetchrow_array ) {
>> ($field1, $field2, $field3, $field4, $field5, $field6, $field7,
>> $field8, $field9, $field10,
>> $field11, $field12, $field13, $field14, $field15, $field16, $field17,
>> $field18) = @array;}
>> $query->finish;
>> $db->disconnect;
>
Don't disconnect yourself from the database in the middle of a while
loop that's iterating through database query results!
Move finish and disconnect out of the loop.

>>
>> print "\nf1 is $field1";
>> $lasttrans = "$field1";
>> $newtrans = ($lasttrans+1);
>> }
>>
>> [...]
>
>
> What you seem to be doing is not very clear.  Why are you running this
> loop
> while (@array = $query->fetchrow_array ) {
> ($field1, $field2, $field3, $field4, $field5, $field6, $field7,
> $field8, $field9, $field10,
> $field11, $field12, $field13, $field14, $field15, $field16, $field17,
> $field18) = @array;}
>
> If you just want the last  transaction id  change the query
> to "select max($field1) from cash where $x = $y ";
>
> This will give you the last transaction id directly
>
>
> BTW 1) Have you considered using an autoincrement field
> 2) Do not connect to the database in every function of yours .
> Make one connection in the beginning and pass the handle to all
> functions.
> 3) And when you post a reply  to a newsgroup post your reply *at the
> bottom* avoid top posting
>
> Ram
>
>
>
>
>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to