php-general Digest 25 Jul 2005 13:35:33 -0000 Issue 3587

Topics (messages 219282 through 219300):

Re: how to post a question?
        219282 by: Richard Lynch
        219285 by: Ryan A
        219297 by: Jochem Maas

Re: Loading dynamic extension
        219283 by: Richard Lynch

Re: Don't ejecute a sentence if a field is empty
        219284 by: Richard Lynch
        219299 by: Jochem Maas

Re: speed - PHP/MYSQL
        219286 by: balwant singh

function MAX with WHERE
        219287 by: Jesús Alain Rodríguez Santos
        219288 by: Georgi Ivanov
        219289 by: Mark Rees

Re: is_array() doesn't work on DOM properties?
        219290 by: Jochem Maas

Re: Installing OLE/Spreadsheet Excel Writer Query
        219291 by: Jochem Maas

running number
        219292 by: Roger Thomas
        219295 by: Richard Davey
        219296 by: Sascha Kaufmann

Closing persistent ODBC connections
        219293 by: Dodot

Re: Delivery Protection
        219294 by: jonathan.ernst.netoxygen.ch

Re: quick question about using capital letters coding w/ PHP
        219298 by: Jochem Maas

A strategy question about using mySQL for saving flat-file stings?
        219300 by: Al

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Fri, July 22, 2005 10:11 am, Ryan A said:
> The str_replace calls are kinda expensive IMHO, a good regex would be
> better

I'd be interested to see a benchmark (any benchmark) where str_replace is
SLOWER than the corresponding Regex...

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Hey Rich,

> > The str_replace calls are kinda expensive IMHO, a good regex would be
> > better

> I'd be interested to see a benchmark (any benchmark) where str_replace is
> SLOWER than the corresponding Regex...

I am not very good with RegEx's myself, and I have never benchmarked any of
them but
I was told or read (when i first started learning php) that using multiple
str_replace()s are
not a good idea and to use a regex instead.
(Thats why I wrote the "IMHO",if i was wrong one of the gurus here could
correct me)

It kind of makes sense, for example using this from the php site:

$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy  = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);

in the above, first it searches the entire phrase for the first parameter
(fruits) then it starts
again fro the second parameter (vegetables) etc, if you have a really long
text it could
be quite process intensive....because it would have to go through the whole
text searching for
the parameters one by one....right?

You're the guy who usually helps me (and a whole lot of others) when we have
questions
so I am really interested on your view on this, and why your view favours
one side more than
the other.

Cheers,
Ryan

--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hey Rich,


The str_replace calls are kinda expensive IMHO, a good regex would be
better


I'd be interested to see a benchmark (any benchmark) where str_replace is
SLOWER than the corresponding Regex...


I am not very good with RegEx's myself, and I have never benchmarked any of
them but
I was told or read (when i first started learning php) that using multiple
str_replace()s are
not a good idea and to use a regex instead.
(Thats why I wrote the "IMHO",if i was wrong one of the gurus here could
correct me)

It kind of makes sense, for example using this from the php site:

$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy  = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);

in the above, first it searches the entire phrase for the first parameter
(fruits) then it starts
again fro the second parameter (vegetables) etc, if you have a really long
text it could
be quite process intensive....because it would have to go through the whole
text searching for
the parameters one by one....right?

You're the guy who usually helps me (and a whole lot of others) when we have
questions

isn't he just! :-) I have to wonder how long his keyboards last ;-), or
whether he retro-fits them with smoke alarms (speedtyping -> overheating ->
fire)

so I am really interested on your view on this, and why your view favours
one side more than
the other.

regexps require a complete engine (in the same way as PHP is a engine)
in order to be parsed. loading/initializing such an engine is heavier than 
doing a 'simple'
search and replace action.... performance results (between str_replace() and 
pre_replace()) will
definitely be skewed when comparing simple regexps against a comparable 
str_replace()
because (to start with) the overhead of calling a function in php (which is why 
its better
to call str_replace() with arrays in param 1 and 2 rather than calling 
str_replace()
multiple times)

...also sporadic CPU load due to totally unrelated processes (even when running 
on
your local machine) can totally skew a benchmark test.

I think you can trust Richard on this one!
and if you don't ... :-) ... then I bet you a beer he'd say "we'll then, why not
test it and see!"




Cheers,
Ryan


--- End Message ---
--- Begin Message ---
On Fri, July 22, 2005 7:32 am, Mathieu Dumoulin said:
> Sorry that doesn't work, just in case i tried erasing anything related
> to Apache, PHP and Perl on my home system. It seems by default, if PHP
> can't find a php.ini it sets all defaults to c:\windows instead of
> setting them to the current application run path.

It might be using the default default (not a typo) if it can't find
php.ini, but that shouldn't alter the values of things like
$_SERVER['script_filename']...

You could also just have your own php.ini on the USB and your own php.exe
on the USB, I guess, if you don't care about anything but Windows...

> I think my next step will be to check if i can recompile PHP manually
> for windows and change the code in it to reflect what i need in terms of
> defaults... Like using the application start path and stuff like that to
> load extensions and more.

Sounds kinda extreme...

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Sat, July 23, 2005 2:18 pm, Jesús Alain Rodríguez Santos said:
> Hello I'm new:
> I need to know how can I stop a php sentence if my db is empty, for
> example
> I have writed a php sentence, if every fields from mmy db are full, there
> is no problem, but I delete every values from the all fields in my db when
> I ejecute my script mysql give me an error, Ej:
>
> $fecha = mysql_query("SELECT event_day, event_month, event_year FROM
> $db_table WHERE event_title = $dia_maximo");
> $fecha_max = mysql_fetch_array($fecha);
> $fecha_maxima = $fecha_max['event_day'];
> $diames_maximo = $fecha_max['event_month'];
>
> wehen I ejecute the script the error message is it:
>
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in /home/www/cfg/prueba/calendar_este2/index.php on line
> 277

After adding the error checking with mysql_error() others have suggested,
the error message you get will, most likely, comlpain that there is no
field named 'XYZ' where XYZ is your $dia_maximo

That's because you need to put apostrophes around text data in SQL.

".. WHERE event.title = '$dia_maximo' ";

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Jesús Alain Rodríguez Santos wrote:
Hello I'm new:
I need to know how can I stop a php sentence if my db is empty, for example
I have writed a php sentence, if every fields from mmy db are full, there

what do you mean by 'php sentence'?

is no problem, but I delete every values from the all fields in my db when
I ejecute my script mysql give me an error, Ej:

$fecha = mysql_query("SELECT event_day, event_month, event_year FROM
$db_table WHERE event_title = $dia_maximo");
$fecha_max = mysql_fetch_array($fecha);
$fecha_maxima = $fecha_max['event_day'];
$diames_maximo = $fecha_max['event_month'];

wehen I ejecute the script the error message is it:

you get this message because $fecha is not what you think it is - I am willing
to bet that it actually contains FALSE), the reason it would contain false is
that your SQL statement is invalid. at the very least it should read something 
like:

"SELECT event_day, event_month, event_year
 FROM $db_table
 WHERE event_title = '$dia_maximo'"

if the value of $dia_maximo is coing from the user then you should be 
sanitizing the
value before using it in a query (see, as a start,
http://nl3.php.net/manual/en/function.mysql-real-escape-string.php)


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in /home/www/cfg/prueba/calendar_este2/index.php on line
277

sorry for my english, I'm cuban

dont be! (your english is better than my spanish! this probably goes for most 
people
onm the list!)

besides for some reason I had to really laugh when I read then the word 
'ejecute'
... laughing is always good! :-)

btw I think you meant 'execute'





--- End Message ---
--- Begin Message --- Actually the data inserted in MYSQL is at every 2 seconds. i.e. 30 rows in an hour. but we are making report on hourly basis. So i used this method.
With best wishes
balwant

--- End Message ---
--- Begin Message ---
I have someting like this:

$test = mysql_query("SELECT MAX(dato) AS datos FROM tabla WHERE campo_mes
= '$mes'");
$test_m = mysql_fetch_array($test);
$test_mes = $test_m['datos'];

print $test_mes

where $mes is a value
I need to know if something its wrong, because I don't recive any error,
but I see nothing




-- 
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.

--- End Message ---
--- Begin Message ---
What print_r($test_m) say ?
Or echo mysql_num_rows($test);
May be you get 0 records from your query.

On Monday 25 July 2005 09:06, Jesús Alain Rodríguez Santos wrote:
> I have someting like this:
>
> $test = mysql_query("SELECT MAX(dato) AS datos FROM tabla WHERE campo_mes
> = '$mes'");
> $test_m = mysql_fetch_array($test);
> $test_mes = $test_m['datos'];
>
> print $test_mes
>
> where $mes is a value
> I need to know if something its wrong, because I don't recive any error,
> but I see nothing
>
>
>
>
> --
> Este mensaje ha sido analizado por MailScanner
> en busca de virus y otros contenidos peligrosos,
> y se considera que está limpio.

-- 
Regards
Georgi Ivanov

--- End Message ---
--- Begin Message ---
"Jesús Alain Rodríguez Santos" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have someting like this:
>
> $test = mysql_query("SELECT MAX(dato) AS datos FROM tabla WHERE campo_mes
> = '$mes'");
> $test_m = mysql_fetch_array($test);
> $test_mes = $test_m['datos'];
>
> print $test_mes
>
> where $mes is a value
> I need to know if something its wrong, because I don't recive any error,
> but I see nothing

Try this, it will tell you if something is wrong

echo  mysql_error();

If nothing is wrong, then perhaps your query returns no rows? Test this by
removing the where clause (assuming there is some data in tabla).

--- End Message ---
--- Begin Message ---
John Smith wrote:
I'm trying to avoid error messages while iterating
over DOM properties. e.g.



if(is_array($dom->stuff->props)) {

maybe you can get roudn the problem by saying?:

if($dom->stuff->props) {

or?:

if(!empty($dom->stuff->props)) {

  foreach($dom->stuff->props as $prop) {
    ...
  }
}

It works without the is_array() check, but not with

my guess is you'll find that $dom->stuff->props is an object
which overloads the array accessor stuff...
basically it's implementing Iterator (or some other SPL Interface)

hard to tell though because you don't mention which DOM
related extension you are using.

it. I've done var_dumps and $dom->stuff->props is
indeed an array. I've also tried using an intermediate
variable ($stuff=$dom->stuff) then checking that, but
that doesn't work either).

John


                
____________________________________________________
Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs

--- End Message ---
--- Begin Message ---
kevin.o'[EMAIL PROTECTED] wrote:
Hi Jochem,

can you telnet to pear.php.net:80 ?


didn't see your reply earlier (been away from the PC). here is the answer:

open a dosbox (type 'CMD' in the run dialog) then type the following in
the dosbox:

telnet pear.php.net 80

if you get a 'Connecting to...' flashing on your cmdline and then an empty
screen then you are connecting fine. the empty screen is actually a prompt
for you to type a request (an HTTP request) e.g. type the following (+ ENTER)
will return the HTML for the index page of that domain:

GET / HTTP/1.1

----
AND PLEASE NEVER ONLY POST A QUESTION DIRECT TO THE GUY/GIRL THAT
IS HELPING YOU ATM.... THEY (i.e. me) ARE NOT YOUR PERSONAL HELPDESK...
POST TO THE LIST (also gives other people to learn from your problems!)


How do I do this? I have selected start > run > cmd > telnet so far.

Kevin.


--- End Message ---
--- Begin Message ---
I am required to write a user registration script that captures the basics like 
name, phone number etc etc. I would also have to write to mySQL database a 
number that is associated with that user.

At this point of writing, the start of that number is unknown. But the number 
will be incremented by 1 after each successfull registration.

Let's say the number starts from 12345.

I am quite new at all these stuff and would like to seek your advise on the 
*recommended way* of achieving this. I am thinking along these lines:
a) store that number (12345) in a table
b) a user registers and assign that number to him
c) increment number to 12346
d) process repeats for the next registration

Concern: How do tell mySQL to lock the 'number' table when a new registration 
process is about to take place. Is locking the best option here or is/are there 
better ways?

Please advise.

--
Roger


---------------------------------------------------
Sign Up for free Email at http://ureg.home.net.my/
---------------------------------------------------

--- End Message ---
--- Begin Message ---
Hello Roger,

Monday, July 25, 2005, 10:21:54 AM, you wrote:

RT> I am quite new at all these stuff and would like to seek your
RT> advise on the *recommended way* of achieving this. I am thinking
RT> along these lines:
RT> a) store that number (12345) in a table
RT> b) a user registers and assign that number to him
RT> c) increment number to 12346
RT> d) process repeats for the next registration

RT> Concern: How do tell mySQL to lock the 'number' table when a
RT> new registration process is about to take place. Is locking the
RT> best option here or is/are there better ways?

Do you HAVE to have a "starting off" number of 12345? If there is no
real reason to do this, then use an auto-increment column in MySQL and
let that do all the hard work for you!

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

--- End Message ---
--- Begin Message ---
try mySQL's auto increment attribute

http://dev.mysql.com/doc/mysql/en/example-auto-increment.html

Roger Thomas wrote:
> I am required to write a user registration script that captures the basics 
> like name, phone number etc etc. I would also have to write to mySQL database 
> a number that is associated with that user.
> 
> At this point of writing, the start of that number is unknown. But the number 
> will be incremented by 1 after each successfull registration.
> 
> Let's say the number starts from 12345.
> 
> I am quite new at all these stuff and would like to seek your advise on the 
> *recommended way* of achieving this. I am thinking along these lines:
> a) store that number (12345) in a table
> b) a user registers and assign that number to him
> c) increment number to 12346
> d) process repeats for the next registration
> 
> Concern: How do tell mySQL to lock the 'number' table when a new registration 
> process is about to take place. Is locking the best option here or is/are 
> there better ways?
> 
> Please advise.
> 
> --
> Roger
> 
> 
> ---------------------------------------------------
> Sign Up for free Email at http://ureg.home.net.my/
> ---------------------------------------------------
> 

--- End Message ---
--- Begin Message ---
Hello everyone,

The php manual isn't very clear about when and how ODBC persistent
connection are actually closed.

I tried with odbc_close_all() but I'm not sure it really closes the
connection, since the next call to odbc_pconnect() will be faster than
before!

The problem is that regularly I really need to close all connections
to the ODBC for maintenance... And I would like to do this without
shutting down apache ;)

Thanks for all your advices!

Jean-Francois, 22, France.

--- End Message ---
--- Begin Message ---
SMTP: Please confirm the attached message.


+++ Attachment: No Virus found
+++ MessageLabs AntiVirus - www.messagelabs.com


--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Sun, July 24, 2005 11:39 am, Dotan Cohen said:

On 7/24/05, Bruce Gilbert <[EMAIL PROTECTED]> wrote:

I am well versed in coding with xhtml which requires all lower case
and am pretty much a newbie at PHP so that is why I am asking this
question.

is this acceptible

if ($_post [sender_email] == "") or does at have to be if ($_POST
[sender_email] == "")

in short, do uppercase and lowercase always have the same meaning.

thx,


PHP is case-sensitive. UppERCase is NOT the same as uppercase. HTML is
not case sensitive only because browsers are forgiving.


PHP variables are case-sensitive.

PHP FUNCTIONS are not.

You're on your own figuring out if class names/methods are/aren't
case-sensitive this week. :-v

1. classname are case-insensitive (at least in all the builds I have running)
but since 5.0.1 (IIRC) the engine honors your case when using get_class(),
in the past the class name was always returned lowercase. so:

php -r 'class Test {} $t = new Test; if ($t instanceof test) { echo "yeah!\n"; } echo 
get_class($t),"\n";'

will echo:

yeah!
Test

2. methodnames are the same as functionname with regard to case-sensitivity

3. constants (and class constants) are case sensitive.

...somebody beat me with a virtual stick if I am wrong!



--- End Message ---
--- Begin Message --- I've been creating a number of CM applications for a virtual-host website. One feature, of several applications, allows the editor [one of our people] to create simple text files. I've been using simple flat-files in a directory for saving the files.

I've gotten tried of dealing with directory permission problems, etc., and am considering using a simple mySQL DB for storing the file strings.

Obviously, for each file-string to be unique, its path must be included as part 
of the ID.

Here is my question.

I can use one table for all the path/files and use the following as the primary key "/home/some-dir/filename".

fields: fullpath-filename | path | type | date | binary-string

path is so the code can do an equivalent of scandir()
type signifies whether data has been serialized() or not.  This is so I can 
save arrays
date is the equivalent of file last mod date.

Or, I can create a separate table for each full-path used and then just use the filename for the primary key. In this case, since the table name is in effect the path, only the filename is needed.

The first approach is obviously simplest; but, I'm concerned about getting myself into a trap later on. Anyone offer any suggestions?

Many thanks.....

--- End Message ---

Reply via email to