PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
I assume your talking about mysql saves it without the leading 0. If you want to preserve the leading 0, change the your numerical column type to use zerofill.
John Cartwright wrote:I assume your talking about mysql saves it without the leading 0. If you want to preserve the leading 0, change the your numerical column type to use zerofill.
John, thank you for the answer. It seems correct but it is not exactly what I need. First of all, it is a Varchar type column for numbers, which saves numbers like this:
045-348-102-6874
or
01(45)3481026874
It may differ a lot, therefore I need the column like string to be able to save numbers with parenthesis, high script and so on.
Just make sure that at every point that you handle the data (PHP, Javascript, MySQL, etc.), you are handling it as a STRING, not a number! That means always enclosing the value in quotation marks. Somewhere along the line, your script is handling it as a numeric value, that's why the leading zero is being dropped. As a string, "0" is just another ASCII character and, believe me, none of these languages will drop an ASCII "0".
Yes, as it is a telephone number, you are not likely to want to use it for Maths functions, which is the whole point of using numbers. If you want to turn a number into a string you can use the function strval().
califdon wrote:Just make sure that at every point that you handle the data (PHP, Javascript, MySQL, etc.), you are handling it as a STRING, not a number! That means always enclosing the value in quotation marks. Somewhere along the line, your script is handling it as a numeric value, that's why the leading zero is being dropped. As a string, "0" is just another ASCII character and, believe me, none of these languages will drop an ASCII "0".
You are right.. the Quotes at the PHP code were missing... now it's working perfectly.