What would be the best way to create an array of all the possible values that a char(1) MySQL database field can hold? I figured I could use range() plus numbers and symbols but I want to maximize the number of possible values I can use.
Based on the ascii chart
http://www.lookuptables.com/
I guess I can use the characters 32 through 126? Or can I use all of them?
Char(1) - Create all possible values..
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$num = range(0, 255);
$chars = array_map('chr', $num);I ran some tests to insert all of these into a database and then pull them back out to make sure they match. The only problem I had is with character 32, which is a space. For some reason when I pull it back out of the database it's null?
Here is the code I used..
Here is the code I used..
Code: Select all
$num = range(0, 255);
$chars = array_map('chr', $num);
foreach ($chars as $key => $value) {
$Database->sendQuery("INSERT INTO `test` (`number`, `character`) VALUES ('" . mysql_real_escape_string($key) . "', '" . mysql_real_escape_string($value) . "')");
}
$Database->sendQuery("SELECT * FROM `test` ORDER BY `number` asc");
while ($Data = $Database->fetchRow()) {
if ($Data['character'] != $chars[$Data['number']]) {
echo 'WARNING!<br />';
echo 'CHARACTER NUMBER ' . $Data['number'] . " does not match. |" . $chars[$Data['number']] . '|' . $Data['character'] . '|<br />';
} else {
echo 'Matched!<br />';
}
}EDIT: I tried not escaping the space but it still isn't working.WARNING!
CHARACTER NUMBER 32 does not match. | ||
Looks like it's a bug in MySQL.
http://bugs.mysql.com/bug.php?id=19564
This is for version 5.0.22 and I am running 4.1.16 so maybe it's been around for a while?!?!
Guess I'll just unset character 32..