|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PHP has a variable as string, and MySQL expects it as interger!
Inside a PHP-script I have constructed an INSERT sql_statement with string vars [formated with format_number()], but when executing the query it dies. I think it's because some vars are expected as intergers by MySQL. How can I convert those vars to execute the query successfully?
Thank you for your help, Freddy |
|
#2
|
||||
|
||||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
what is the data in the vars? If you don't explicitly force a data type PHP will change type to suit the needs of the operation. You could always edit the db to make the field types text.
B |
|
#3
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
Is changing the data type in the database the only solution?
There is a posibility that the MySQL database(tables) is going to be used by other applications in another plataform. *- When I query the data the first time around some are intergers and floats, but when I show them into a form they are converted automatically to strings, and that's no good with MySQL to inserting or modifing queries. The NUMBER_FORMAT() build-in function automatically converts the vars to strings! *- I appreciate your help very much. Have a nice day, Freddy |
|
#4
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
Could you please post your SQL query, so that we can take a look
|
|
#5
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
hmm ...
the db field is type int/float, you number_format() the field for presentation, your allowing a user to modify the altered field and then inserting the user-modified number back into the db? I pull int's from my db and display them in a textbox for the user to change and write the number back to the db with no problem. One reason why I love PHP, don't have to worry about casting. I'm sure php does have a cast() that you can use ... I just checked the php manual and was not able to find a cast(). Anybody know how to cast in PHP? |
|
#6
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
Quote:
no, this is not a reason why query dies... mysql does his own type casting if u used ' to surround fields like: insert into table set field1='data1', field2='data2'... and if u pass a string in a field that is a int, it would convert it to 0, but it wont die... and if u don't use ' around field data, i think it could die, but u SHOULD! as for type casting in php, just add a "(type)" in front of variable or expression u want to typecast, like this: $real = 7.5; $int = (int) $real / 2; |
|
#8
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
That was me ... how 'bout those cookies?
|
|
#9
|
|||
|
|||
|
RE: PHP has a variable as string, and MySQL expects it as interger!
Thank you to all.
My problem was on the numbers of fields passed to the query and the number expected by MySQL. Now I'm asured that PHP and MySQL do convert automatically variables as needed (at least strings to intergers or floats and reversilly). Freddy |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > PHP has a variable as string, and MySQL expects it as interger! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|