I have the following table called pr_collaborator
:
--------------------------------
id | name | last_name |
--------------------------------
000015| John | Smith |
002154| Maria | Sanchez |
123456| Fabian | Sierra |
SE0012| Sarah | Taylor |
SE0015| Conny | Huertas |
--------------------------------
I just made this query:
SELECT * FROM pr_collaborator;
And this is the result:
--------------------------------
id | name | last_name |
--------------------------------
15 | John | Smith |
2154| Maria | Sanchez |
123456| Fabian | Sierra |
SE0012| Sarah | Taylor |
SE0015| Conny | Huertas |
--------------------------------
I want to keep the leading zeros, the id
field is VARCHAR(10)
I was trying the following but it does not work;
SELECT CAST(id as CHAR) AS id, name, last_name FROM pr_collaborator;
SELECT CONVERT(id, VARCHAR) AS id, name, last_name FROM pr_collaborator;
I don't want to use LPAD
function because I don't know how many characters have the values.
Update
This is the pr_collaborator
structure:
CREATE TABLE `pr_collaborator` (
`id` varchar(10) COLLATE utf8_spanish_ci NOT NULL,
`name` varchar(80) CHARACTER SET latin1 NOT NULL,
`last_name` varchar(80) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci
This is the query in PHP code:
$sql = "SELECT id, name, last_name FROM pr_collaborator";
$result = $this->db->fetchAll($sql, Phalcon\DB::FETCH_ASSOC);
$this->jsonReturnSuccess($result);
Maybe it could be a problem with PHP and no with my MySQL
I hope that you can help me!.