Storing database pk IDs in php code alternative?
We have hundreds of thousands of lookup values and since the product is still in dev the IDs are not 开发者_开发百科fixed. So anytime an ID is updated we have to go back and updated thousands of IDs all over the code to make it work properly. It eats away on time.
Is there another method to keep IDs as dynamic in the code so either: they auto update as IDs are changed in the tables, or they are all stored in 1 file for all database tables so it makes updates much easier and quicker from development and testing perspective?
Platform is Mysq + codeignitor php.
Define constants in your code for the ids instead of hard-coding id values. Here's an example:
<?php
$result = mysql_query("SELECT Id, Name FROM Product");
while($row = mysql_fetch_assoc($result)){
define('ID_'.$row['Name'],$row['Id']);
}
?>
精彩评论