SQL binary value to PHP variable leading zeros

Posted by Agony on Pro Webmasters See other posts from Pro Webmasters or by Agony
Published on 2012-12-03T11:08:48Z Indexed on 2012/12/03 12:05 UTC
Read the original article Hit count: 197

Filed under:
|

Using sql query to pull data from a mssql database results in a value that still has leading zeros. The data in database is stored as binary(13) - so it will pull all 13 digits.

However the value is a text, so any leading zeros will generally show up as '?' in a form on the site - and in return will update wrong data to the database later.

So what i need is to only select/display the text itself, not all 13 bytes. using: SELECT CONVERT(char,uilock_pw) AS uipwd FROM tbl_UserAccount or SELECT uilock_pw FROM tbl_UserAccount still adds the leading zeros to the char array.

Example in database: 0x71776531323300000000000000 Would show up as: qwe123??????? But should be: qwe123 Im not even sure what character those ? represent. Using Echo results in a normal qwe123 - but not in a form.

© Pro Webmasters or respective owner

Related posts about php

Related posts about sql