You are here: Re: MySql VCHAR column converted to float by PHP :-( « PHP Programming Language « IT news, forums, messages
Re: MySql VCHAR column converted to float by PHP :-(

Posted by Andy Hassall on 03/01/06 21:27

On 1 Mar 2006 08:24:40 -0800, rass.elma@googlemail.com wrote:

>Hi all
>I fetch the following value from a string (VCAHR(250))colmun in a MySql
>table:
> "300000000000000000000000000000000000000000000000000"
>
>When I write it out using echo() I get :
> 3E+50
>
>Appearently the PHP interpreter converts the VCAHR value automatically
>in a float despite the fact that the value is defined as a VCAHR in
>MySql.
>While trying to convert float to string back in PHP using type casting
>or settype() I get always the string "3E+50".
>
>Does someone know how one can fetch the VCHAR as string?
>Does someone know how to print a formatted float to get the desired
>result? I tried printf() but no success.

You're going to have to post a minimal example demonstrating it, along with
your PHP and MySQL version because on my system it shows the full string as
expected:

andyh@server ~ $ mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40 to server version: 4.1.7

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> connect test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> drop table t;
Query OK, 0 rows affected (0.03 sec)

mysql> create table t (c varchar(250));
Query OK, 0 rows affected (0.04 sec)

mysql> insert into t values
('300000000000000000000000000000000000000000000000000');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+-----------------------------------------------------+
| c |
+-----------------------------------------------------+
| 300000000000000000000000000000000000000000000000000 |
+-----------------------------------------------------+
1 row in set (0.01 sec)

mysql> exit
Bye

andyh@server ~ $ cd public_html/
andyh@server ~/public_html $ cat test.php
<?php
$conn = mysql_connect();
mysql_select_db('test');
$res = mysql_query('select * from t');
$row = mysql_fetch_assoc($res);
var_dump($row);
print "\n";
print $row['c'];
print "\n";
?>
andyh@server ~/public_html $ php -q test.php
array(1) {
["c"]=>
string(51) "300000000000000000000000000000000000000000000000000"
}

300000000000000000000000000000000000000000000000000

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация