php-general Digest 2 May 2007 08:56:58 -0000 Issue 4768
Topics (messages 254209 through 254216):
Re: PHP Command line script
254209 by: Daniel Brown
254212 by: Nathaniel Hall
254213 by: Greg Donald
Deviation? Distribution? OT?
254210 by: Richard Lynch
254211 by: Daniel Brown
Sending the results of a query without using a file
254214 by: Todd Cary
254215 by: Kevin Waterson
Split string
254216 by: Lester Caine
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
First and foremost, it's a VERY BAD idea to use root for MySQL. If your
code isn't perfect (and even sometimes if it is), arbitrary commands and SQL
injection attacks could lead to migraines that no Tylenol will ever be able
to alleviate.
Secondly, what error is the CLI kicking out when you run it from the
command line?
On 5/1/07, Nathaniel Hall <[EMAIL PROTECTED]> wrote:
I am attempting to run a script that will run from the command line
nightly to update a field in a database. I already created a script
that would access the database and insert most of the information when a
webpage is visited and I had no problems with it. The command line
script appears to fail on the prepare. I have echo'ed the SQL statement
to the screen, copied it, and run it on the MySQL server with no
problems. Any ideas?
<?php
$mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
if (mysqli_connect_errno()) {
echo "Unable to connect to database.\n";
exit;
} else {
$login = date('m\-d\-Y');
if ($logout = $mysqli->prepare("UPDATE `mydb`.`authlog`
SET `logout` = ? WHERE `login` LIKE '$login%'")) { // <--- Will not go
any further than here, even when hard coding the information.
$logout->bind_param("s",
date('m\-d\-Y\TH\:i\:s'));
$logout->execute();
$logout->close();
}
}
$mysqli->close();
?>
--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
Daniel Brown wrote:
First and foremost, it's a VERY BAD idea to use root for MySQL.
If your code isn't perfect (and even sometimes if it is), arbitrary
commands and SQL injection attacks could lead to migraines that no
Tylenol will ever be able to alleviate.
I changed the user I was connecting as in order to post. I don't use
root in the real code.
Secondly, what error is the CLI kicking out when you run it from
the command line?
It doesn't give an error. The only thing it does is continue on through
the IF statement, which goes nowhere. I have added an ELSE to the
script and run it. It ends up running the code in the ELSE.
$login = date('m\-d\-Y');
if ($logout = $mysqli->prepare("UPDATE `mydb`.`authlog` SET
`logout` = ? WHERE `login` LIKE '$login%'")) { // <--- Will not
go any further than here, even when hard coding the information.
$logout->bind_param("s", date('m\-d\-Y\TH\:i\:s'));
$logout->execute();
$logout->close();
}
--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security
--- End Message ---
--- Begin Message ---
On 5/1/07, Nathaniel Hall <[EMAIL PROTECTED]> wrote:
I am attempting to run a script that will run from the command line
nightly to update a field in a database. I already created a script
that would access the database and insert most of the information when a
webpage is visited and I had no problems with it. The command line
script appears to fail on the prepare. I have echo'ed the SQL statement
to the screen, copied it, and run it on the MySQL server with no
problems. Any ideas?
<?php
$mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
if (mysqli_connect_errno()) {
echo "Unable to connect to database.\n";
exit;
} else {
$login = date('m\-d\-Y');
if ($logout = $mysqli->prepare("UPDATE `mydb`.`authlog`
SET `logout` = ? WHERE `login` LIKE '$login%'")) { // <--- Will not go
any further than here, even when hard coding the information.
$logout->bind_param("s", date('m\-d\-Y\TH\:i\:s'));
$logout->execute();
$logout->close();
}
}
$mysqli->close();
?>
Add full error reporting, then make sure you can see the errors, then
test to see if you have the mysqli extension:
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
ini_set( 'log_errors', 1 );
if( !in_array( 'mysqli', get_loaded_extensions() ) )
{
die( 'no mysqli found' );
}
Also, why do you need to escape the dashes in the date() calls?
php -r 'echo date("Y-m-d");'
2007-05-01
--
Greg Donald
http://destiney.com/
--- End Message ---
--- Begin Message ---
My boss and the web designer have decided to do something that
requires statistical formulae well beyond my statistically-challenged
capabilities, so I'm turning to y'all...
Basically, the current query looks something like this:
select * from
(select whatever, count(*) as popular
from the_table
group by whatever
order by popular desc
limit 100
) as pop
order by rand()
So basically it's the "Top 100" popular, ordered at random
They then want to have the MOST popular stuff with a CSS class="t5"
and the least popular with class="t1"
The t5 are BIG AND BOLD and the t1 are >> tiny and plain << basically,
with t2, t3, and t4 sort of "in between" in bigness and boldness.
The CSS guy has that bit worked out, in terms of style.
I just have to label the dang things t1 to t5, no more, no less.
Now I have NO IDEA what the range is going to be for the "popuplar"
score as time goes on and the site gets super-popular...
So I guess I want some kind of standard deviation thingie among those
Top 100?
I know for sure I don't want just 20 of each t1 through t5.
There are way more t1 than there are t5.
So maybe it's more logarithmic than standard deviation?
Or is there some kind of weighted deviation?
Or maybe it's some other statistical thingie like standard deviation
only not?
All I now for sure is, my current hack of taking log($popular, 3) in
PHP is only going to sort of "work" with our sample data and make them
THINK that it's working, when it's actually quite borked as soon as
the number of data points increases. (I.e., next week or so)
Little help here?
I suspect it's going to turn out to be some magical MySQL statistics
function, but not knowing what "standard deviation" actually *means*
any more, I'm at a loss to guess which one...
I guess I *could* take the results in order without the wrapping
rand() query, do min/max and log games in PHP on the highest/lowest,
and then do a shuffle... But there's got to be a better way.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
I don't think I'm quite following why you wouldn't just want to break it
up into groups of 20....
On 5/1/07, Richard Lynch <[EMAIL PROTECTED]> wrote:
My boss and the web designer have decided to do something that
requires statistical formulae well beyond my statistically-challenged
capabilities, so I'm turning to y'all...
Basically, the current query looks something like this:
select * from
(select whatever, count(*) as popular
from the_table
group by whatever
order by popular desc
limit 100
) as pop
order by rand()
So basically it's the "Top 100" popular, ordered at random
They then want to have the MOST popular stuff with a CSS class="t5"
and the least popular with class="t1"
The t5 are BIG AND BOLD and the t1 are >> tiny and plain << basically,
with t2, t3, and t4 sort of "in between" in bigness and boldness.
The CSS guy has that bit worked out, in terms of style.
I just have to label the dang things t1 to t5, no more, no less.
Now I have NO IDEA what the range is going to be for the "popuplar"
score as time goes on and the site gets super-popular...
So I guess I want some kind of standard deviation thingie among those
Top 100?
I know for sure I don't want just 20 of each t1 through t5.
There are way more t1 than there are t5.
So maybe it's more logarithmic than standard deviation?
Or is there some kind of weighted deviation?
Or maybe it's some other statistical thingie like standard deviation
only not?
All I now for sure is, my current hack of taking log($popular, 3) in
PHP is only going to sort of "work" with our sample data and make them
THINK that it's working, when it's actually quite borked as soon as
the number of data points increases. (I.e., next week or so)
Little help here?
I suspect it's going to turn out to be some magical MySQL statistics
function, but not knowing what "standard deviation" actually *means*
any more, I'm at a loss to guess which one...
I guess I *could* take the results in order without the wrapping
rand() query, do min/max and log games in PHP on the highest/lowest,
and then do a shuffle... But there's got to be a better way.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
Some shared servers do not allow the creation of a file, so I am
looking for a way to take the results of a query (MySQL), create
a CSV output and have it in a sendable format for the user
without creating a file.
Many thanks....
Todd
--- End Message ---
--- Begin Message ---
This one time, at band camp, Todd Cary <[EMAIL PROTECTED]> wrote:
> Some shared servers do not allow the creation of a file, so I am
> looking for a way to take the results of a query (MySQL), create
> a CSV output and have it in a sendable format for the user
> without creating a file.
sendable to where?
kevin
--
"Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote."
--- End Message ---
--- Begin Message ---
Can someone with a few more working grey cells prompt me with the correct
command to split a string.
The entered data is names, but I need to split the text up to the first space
or comma into one string, and the rest of the string into a second. It's the
'first either space or comma' that eludes me at the moment :(
In know it's probably obvious, but it always is when you know the answer.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://home.lsces.co.uk
MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Firebird Foundation Inc. - http://www.firebirdsql.org/index.php
--- End Message ---