php - mysql custom global defined variable -
in database design, tend store variable meant acting role or type smallint
. example :
create table `house` ( `id` int(11) not null auto_increment, `type` smallint(11) not null,
and in php,
define('house_small_type', '0'); define('house_medium_type', '1');
so in php, in select queries :
$this->db->query("select * house type=?;", house_small_type);
my questions :
- in php part, there better way ?
- in mysql itself, mysql has global define functionality (like define in php) ?
i want kind of
select * house type = house_small_type
in mysql query.
purpose when select in mysql, no way i'm going keep mapping value 0,1,2 real meaning. convineance viewing tables values, without changing structure table , fields.
i suggest using mysql variables:
set house_small_type = 0; set house_medium_type = 1;
then, in queries may use these variables:
select * house type = @house_small_type;
this method defines session variables:
if change session system variable, value remains in effect until session ends or until change variable different value. change not visible other clients.
if want define global mysql variables (available sessions):
set global house_small_type = 0; set global house_medium_type = 1;
to indicate explicitly variable global variable, precede name global or @@global.. super privilege required set global variables.
documentation:
set statement
using system variables
user-defined variables
Comments
Post a Comment