php-general Digest 31 Aug 2011 23:58:28 -0000 Issue 7464

Topics (messages 314669 through 314685):

Re: mysqli sql question
        314669 by: James Yerge
        314673 by: Peet Grobler
        314675 by: Jen Rasmussen
        314678 by: Richard Riley
        314679 by: Louis Huppenbauer
        314680 by: james.nixsecurity.org
        314681 by: Jen Rasmussen

Re: utf8_decode() not working, conflicts with urlencode()
        314670 by: Merlin Morgenstern
        314671 by: Merlin Morgenstern

Hide php action pages from google
        314672 by: Merlin Morgenstern
        314676 by: Jen Rasmussen

Re: Code should be selv-maintaining!
        314674 by: Jen Rasmussen

Bug #51739 tricky string to float conversion
        314677 by: magic-php.damage.devloop.de
        314683 by: Shawn McKenzie
        314685 by: Shawn McKenzie

Re: scroll down list -visible, but not possible to choose
        314682 by: Ken Kixmoeller
        314684 by: Geoff Shang

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 08/31/2011 05:23 AM, Peet Grobler wrote:
> Is it possible to get the actual sql that is being used to query or
> update the database?
>
> E.g
> $sth = $dbh->prepare ("update table set field=?, field2=? where id=?);
> mysqli_bind_param ($sth, 'ssi', 'text1', 'text2', 10);
> $sth->execute();
>
> Something like $sth->sql? Or $dbh->sql?
>
> I want to see "update table set field='text1', field2='text2' where id=10;
>
>
> Thanks in advance,
> Peet
>
Look up the EXPLAIN SQL function call.

--- End Message ---
--- Begin Message ---
On 8/31/2011 1:38 PM, John Black wrote:
> Hi Peet,
> 
> not sure if there is a method to echo the sql but you can set your
> development MySQL server to log all queries to a log file.
> Use the log file with tail and you'll get a live view of all queries the
> server attempts to process.
> 

I already have this on the development system. I'm looking for something
for the live system that displays the SQL if a query fails (this is done
in an email to the developer's mailing list)

--- End Message ---
--- Begin Message ---
Peet,

Could you do something like this instead? This is using named placeholders
and a separate line for your statement
but I was able to get it to echo the statement in this manner. 

$sql = "UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id";
                $sth = $dbh->prepare($sql);
                $sth->execute(array(":field1"=>$field1,
                                           ": field2"=>$ field2,
                                           ": id"=>$id));

echo $sql; 

Hope that helps,
Jen

-----Original Message-----
From: Peet Grobler [mailto:p...@hivemind.net] 
Sent: Wednesday, August 31, 2011 4:24 AM
To: php-gene...@lists.php.net
Subject: [PHP] mysqli sql question

Is it possible to get the actual sql that is being used to query or
update the database?

E.g
$sth = $dbh->prepare ("update table set field=?, field2=? where id=?);
mysqli_bind_param ($sth, 'ssi', 'text1', 'text2', 10);
$sth->execute();

Something like $sth->sql? Or $dbh->sql?

I want to see "update table set field='text1', field2='text2' where id=10;


Thanks in advance,
Peet

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
"Jen Rasmussen" <j...@cetaceasound.com> writes:

> Peet,
>
> Could you do something like this instead? This is using named placeholders
> and a separate line for your statement
> but I was able to get it to echo the statement in this manner. 
>
> $sql = "UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id";
>               $sth = $dbh->prepare($sql);
>               $sth->execute(array(":field1"=>$field1,
>                                          ": field2"=>$ field2,
>                                          ": id"=>$id));

Hi Jen, could you point me to a document/man page for PHP which explains
that : notation in $sql= line please. I'm sure its common to everyone
here but, well, I never saw it before ;(


--- End Message ---
--- Begin Message ---
Hi there Richard

It's part of the prepared statements
http://php.net/manual/de/pdo.prepared-statements.php
;)

2011/8/31 Richard Riley <rile...@googlemail.com>

> "Jen Rasmussen" <j...@cetaceasound.com> writes:
>
> > Peet,
> >
> > Could you do something like this instead? This is using named
> placeholders
> > and a separate line for your statement
> > but I was able to get it to echo the statement in this manner.
> >
> > $sql = "UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id";
> >               $sth = $dbh->prepare($sql);
> >               $sth->execute(array(":field1"=>$field1,
> >                                          ": field2"=>$ field2,
> >                                          ": id"=>$id));
>
> Hi Jen, could you point me to a document/man page for PHP which explains
> that : notation in $sql= line please. I'm sure its common to everyone
> here but, well, I never saw it before ;(
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
>---- Original Message ----
>From: Louis Huppenbauer <louis.huppenba...@gmail.com>
>To: php-gene...@lists.php.net
>Sent: Wed, Aug 31, 2011, 10:24 AM
>Subject: Re: [PHP] Re: mysqli sql question
>
>Hi there Richard
>
>It's part of the prepared statements
>http://php.net/manual/de/pdo.prepared-statements.php
>;)
>
>2011/8/31 Richard Riley <rile...@googlemail.com>
>
>> "Jen Rasmussen" <j...@cetaceasound.com> writes:
>>
>> > Peet,
>> >
>> > Could you do something like this instead? This is using named
>> placeholders
>> > and a separate line for your statement
>> > but I was able to get it to echo the statement in this manner.
>> >
>> > $sql = "UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id";
>> >               $sth = $dbh->prepare($sql);
>> >               $sth->execute(array(":field1"=>$field1,
>> >                                          ": field2"=>$ field2,
>> >                                          ": id"=>$id));
>>
>> Hi Jen, could you point me to a document/man page for PHP which explains
>> that : notation in $sql= line please. I'm sure its common to everyone
>> here but, well, I never saw it before ;(
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

These are called SQL Parameters. It's recommended to use them since they help 
eliminate SQL Injections.


--- End Message ---
--- Begin Message ---
Peet,

Here is the PHP PDO link: http://php.net/manual/en/book.pdo.php

If you look on example #2 on this page:
http://www.php.net/manual/en/pdostatement.execute.php
That is pretty much how it's setup (although the example I gave is update,
this is select). 
And please correct me I said the provided code example included named
placeholders, apparently correct terminology is named parameters.  

I found this to be a great article as well:
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-d
atabase-access/

If you need some more example code as well, just let me know. I've been up
to my ears in PDO the last several weeks.

Jen 



-----Original Message-----
From: Richard Riley [mailto:rile...@googlemail.com] 
Sent: Wednesday, August 31, 2011 9:18 AM
To: php-gene...@lists.php.net
Subject: [PHP] Re: mysqli sql question

"Jen Rasmussen" <j...@cetaceasound.com> writes:

> Peet,
>
> Could you do something like this instead? This is using named placeholders
> and a separate line for your statement
> but I was able to get it to echo the statement in this manner. 
>
> $sql = "UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id";
>               $sth = $dbh->prepare($sql);
>               $sth->execute(array(":field1"=>$field1,
>                                          ": field2"=>$ field2,
>                                          ": id"=>$id));

Hi Jen, could you point me to a document/man page for PHP which explains
that : notation in $sql= line please. I'm sure its common to everyone
here but, well, I never saw it before ;(


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Am 30.08.2011 12:11, schrieb Per Jessen:
Merlin Morgenstern wrote:

Hi there,

I am having some trouble with utf8_decode(). Somehow the function
returns output=input

e.g.:
$input = '%20%C3%9Cbersetzung%20franz';
$output = utf8_decode($input);
echo $input.'<br>'.$output;

My goal is to decode the utf8, trim the input and encode with
urlencode();

This is the string which I would like to get: %C3%9Cbersetzung+franz

Trim does not work and if I place urlencode() directly on the input it
will encode the % sign to %25 and produce therfore a mixture of
encodings.

It seems to me that you're probably missing a urldecode() on $input
before you attempt to decode the utf8 chars ?




that is true, thank you.

--- End Message ---
--- Begin Message ---
Am 30.08.2011 12:11, schrieb Per Jessen:
Merlin Morgenstern wrote:

Hi there,

I am having some trouble with utf8_decode(). Somehow the function
returns output=input

e.g.:
$input = '%20%C3%9Cbersetzung%20franz';
$output = utf8_decode($input);
echo $input.'<br>'.$output;

My goal is to decode the utf8, trim the input and encode with
urlencode();

This is the string which I would like to get: %C3%9Cbersetzung+franz

Trim does not work and if I place urlencode() directly on the input it
will encode the % sign to %25 and produce therfore a mixture of
encodings.

It seems to me that you're probably missing a urldecode() on $input
before you attempt to decode the utf8 chars ?




that is true, thank you.

--- End Message ---
--- Begin Message ---
Hi there,

I do have a search form on my site which posts search queries to follogin URL:

/subapp_search/search.php

Depending on the search parameters it will then redirect to the appropriate URL. e.g.: /suche/labrador

I now discovered in google webmastertools that this very page (search.php) is listed there as a reference for the speed of the whole page with 2.7s.

This page should be irrelevant to google. Does somebody know how to hide it from google? All redirects coming from there are 301s and the page without parameters redirects to /

Thank you for any help on that,

Merlin

--- End Message ---
--- Begin Message ---
Merlin,

Do you have a robots.txt file in your root folder?
A text document named robots.txt in your document root containing the
following text
should solve your problem. 


# robots.txt for http://www.yourdomain.com/

User-agent: *
Disallow: /subapp_search/search.php

User-Agent: Googlebot
Disallow: /subapp_search/search.php


More info here:
http://www.google.com/support/webmasters/bin/answer.py?answer=156449


Jen


-----Original Message-----
From: Merlin Morgenstern [mailto:merlin.morgenst...@googlemail.com] 
Sent: Wednesday, August 31, 2011 7:39 AM
To: php-gene...@lists.php.net
Subject: [PHP] Hide php action pages from google

Hi there,

I do have a search form on my site which posts search queries to 
follogin URL:

/subapp_search/search.php

Depending on the search parameters it will then redirect to the 
appropriate URL. e.g.: /suche/labrador

I now discovered in google webmastertools that this very page 
(search.php)  is listed there as a reference for the speed of the whole 
page with 2.7s.

This page should be irrelevant to google. Does somebody know how to hide 
it from google? All redirects coming from there are 301s and the page 
without parameters redirects to /

Thank you for any help on that,

Merlin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Genius! 

-----Original Message-----
From: Matt Graham [mailto:danceswithcr...@usa.net] 
Sent: Tuesday, August 30, 2011 5:59 PM
To: php-gene...@lists.php.net
Subject: Re: [PHP] Code should be selv-maintaining!

From:  David Harkness <davi...@highgearmedia.com>
> I don't always use braces, but when I do I use Compact Control Readability
> style. Stay coding, my friends.

...and when you use CCR style, you can sing, "I see a bad brace a-risin'"?

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Hi,
I have opend Bug #51739 in 2010. It was closed as bogus before my last question was answered. It would be fine to know what you think about that bug.
In short:
var_dump((float)"8315e839da08e2a7afe6dd12ec58245d"); results in float(INF) This is because "8315" is treated as base and "e839da08e2a7afe6dd12ec58245d" is treated as an exponent. My hint that "e839da08e2a7afe6dd12ec58245d" is not a valid exponent was not answered. What do you think about?
cheers
Daniel

--- End Message ---
--- Begin Message ---
On 08/31/2011 09:03 AM, magic-...@damage.devloop.de wrote:
> Hi,
> I have opend Bug #51739 in 2010. It was closed as bogus before my last
> question was answered. It would be fine to know what you think about
> that bug.
> In short:
> var_dump((float)"8315e839da08e2a7afe6dd12ec58245d");
> results in float(INF)
> This is because "8315" is treated as base and
> "e839da08e2a7afe6dd12ec58245d" is treated as an exponent. My hint that
> "e839da08e2a7afe6dd12ec58245d" is not a valid exponent was not answered.
> What do you think about?
> cheers
> Daniel

The cast to float is truncating the invalid characters and since your
string contains a float that is INF (8315e839) before the truncation at
the "d", then it returns INF.  Makes perfect sense.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On 08/31/2011 01:48 PM, Shawn McKenzie wrote:
> 
> The cast to float is truncating the invalid characters and since your
> string contains a float that is INF (8315e839) before the truncation at
> the "d", then it returns INF.  Makes perfect sense.
> 

Just FYI...  Don't post your troubles or misunderstandings as bug
reports.  The PHP developers sift through too many reports as it is and
many or maybe the majority are "support" tickets like yours that are not
"bugs".  The people assigned to bugs are not going to explain why your
issue is not a bug in detail.  They are tasked with fixing bugs, and
they have many bug reports (mostly like yours).  The appropriate place
for you to post would be here on this list first.  If the consensus of
the veteran folks on this list is "wow, that's a bug" or some such, then
we will tell you to post a bug report.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
You want:

>  if($status == $selected) echo "selected = ' selected' ";
(I didn't bother with \s)

And BTW, unless the support person is actually sitting on top of the
customer (and I can see situations where that would help), you want it
to say "Waiting *for* Customer"

Ken

On Wed, Aug 31, 2011 at 3:30 AM,  <rob...@myself.com> wrote:
>  echo "<option value=\"$status\"";
>  if($status == $selected) echo ' selected';
>  echo ">$status</option>";
>  }
>  }
>

--- End Message ---
--- Begin Message ---
On Wed, 31 Aug 2011, rob...@myself.com wrote:

I have the below function with array for satus of issues where I need to have 
'Resolved/Closed' visible but not available for choice
This as closing is a separate function to ensure correct resolution code is 
selected

Already tried removing 'Resolved', and got everything working only to notice 
when testing that when viewing issues the Resolved
ones showed up as 'Support Working' even though closed in the system

There are two possible points of failure here, your code and browser behaviour. Whenever I'm faced with this sort of problem, I look at the source code in my browser to see the HTML my code generates. Then I can determine if my code is outputting what I'd intended. If it is, then my code is right but the implementation is wrong, as the correct HTML produces the incorrect result.

If you'd done this, you'd have seen what the problem is. The problem is that, having taken away "Resolved" as a possible option, all items marked "Resolved" are unable to be listed as selected. Consequently no items are selected and the browser defaults to the first item in the list which is "Support Working".

I've never had to do this, but http://www.w3schools.com/TAGS/tag_option.asp says you can use the "disabled" attribute to disable an option. So your resulting HTML could look like this:

<option value="Resolved" disabled>Resolved</option>

or

<option value="Resolved" disabled selected>Resolved</option>

as appropriate. A simple if statement could be used to set the "disabled" attribute for the "Resolved" selection only.

IMHO this is vastly preferable to any trickery you may use with javascript to prevent the user from selecting Resolved.

I've never struck a select field like this and am now interested in coding one up just to see how it works in practice.

HTH,
Geoff.

--- End Message ---

Reply via email to