[ciapug] weakly typed languages, etc.
carl-olsen at mchsi.com
carl-olsen at mchsi.com
Wed Apr 4 13:39:48 CDT 2007
I see what you mean. It's inside a quoted string, so it gets passed exactly as written. So, my theory is invalid and MySQL is not the reason for it. All I know is that PHP converts "123" into 123 and considers it an integer. I'm not sure why they thought that was a good idea. All I can think of at the moment is that it makes it easier to to use something like $_GET["id"] in a calculation without converting it from a string to an integer first.
-------------- Original message ----------------------
From: David Champion <dchampion at visionary.com>
> Right. What I was talking about is that PHP isn't converting the '1' to 1.
>
> i.e.
>
> $sql = "SELECT * FROM table WHERE id = '1'";
> echo ("<br>sql : " . $sql);
>
> Guess what, the '1' is still there. That's how it gets passed to the
> database engine.
>
> If you run the query with the '1' in it in MySQL, it works the same as
> if you put 1.
>
> It's a good idea to understand how strings are evaluated in PHP. What
> you stated was incorrect, and could mislead people.
>
> If you are connecting to another database like MS-SQL, and try that
> query with the '1' in it, it will fail.
>
> -dc
>
> carl-olsen at mchsi.com wrote:
> > I was talking about doing a query using PHP functions. I don't know how MySQL
> handles quoted integers from the command line. Some databases would give me an
> error if I put quotes around an integer, but PHP would take care of that for me
> by converting it to an integer. I assume the behavior is intentional.
> >
> > -------------- Original message ----------------------
> > From: David Champion <dchampion at visionary.com>
> >> That's not being evaluated by PHP, it's being evaluated by MySQL.
> >> Different issue.
> >>
> >> If you go into MySQL and type the query with the quotes around the value
> >> it will work just fine.
> >>
> >> -dc
> >>
> >> carl-olsen at mchsi.com wrote:
> >>> I've noticed a lot of books do a MySQL query like so "SELECT * FROM table
> >> WHERE id = '1'".
> >>> If PHP did not convert that quoted number into an integer, it would throw an
> >> error.
> >>> Most other databases would through an error if you put quotes around an
> >> integer in the WHERE clause.
> >>>
> >>> -------------- Original message ----------------------
> >>> From: carl-olsen at mchsi.com
> >>>> concatenate "s" to the beginning of each string, then do the comparison,
> and
> >>>> finally strip "s" from the beginning of each string. Actually, adding any
> >>>> "alpha" character to the string will prevent PHP from converting it to a
> >> number.
> >>>> _______________________________________________
> >>>> ciapug mailing list
> >>>> ciapug at cialug.org
> >>>> http://cialug.org/mailman/listinfo/ciapug
> >>>
> >>> _______________________________________________
> >>> ciapug mailing list
> >>> ciapug at cialug.org
> >>> http://cialug.org/mailman/listinfo/ciapug
> >>>
> >>
> >> _______________________________________________
> >> ciapug mailing list
> >> ciapug at cialug.org
> >> http://cialug.org/mailman/listinfo/ciapug
> >
> >
> > _______________________________________________
> > ciapug mailing list
> > ciapug at cialug.org
> > http://cialug.org/mailman/listinfo/ciapug
> >
>
>
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug
More information about the ciapug
mailing list