PHP Database Helper Class
Usually we have edit and insert page for administration area.
While constructing the SQL query for editing and inserting for a same table with lots of fields may consume lot of time, why don’t we make it easier ?
So i create this class to help you with construction the SQL query for editing and inserting data.
Here’s the example usage of editing query
$dh = new dbhelper();
$dh->table_name = 'bet_type';
$dh->setFields(
array('name' => 'bet_type_name', 'value' => $bt_name),
array('name' => 'minimum_bet', 'value' => $bt_minimum_bet, 'type' => 'int'),
array('name' => 'maximum_bet', 'value' => $bt_maximum_bet, 'type' => 'int'),
array('name' => 'prize_percentage', 'value' => $bt_prize_percentage, 'type' => 'int'),
array('name' => 'choice_length', 'value' => $bt_choice_length, 'type' => 'int'),
array('name' => 'bet_note', 'value' => $bt_note),
array('name' => 'bet_link_note', 'value' => $bt_link_note),
array('name' => 'bet_type_status', 'value' => $bt_status),
array('name' => 'sort_order', 'value' => $bt_sort_order, 'type' => 'int')
);
$q = $dh->sqlUpdate();
mysql_query($q);
Here’s the example usage of inserting query
$dh = new dbhelper();
$dh->table_name = 'bet_type';
$dh->setFields(
array('name' => 'bet_type_name', 'value' => $bt_name),
array('name' => 'minimum_bet', 'value' => $bt_minimum_bet, 'type' => 'int'),
array('name' => 'maximum_bet', 'value' => $bt_maximum_bet, 'type' => 'int'),
array('name' => 'prize_percentage', 'value' => $bt_prize_percentage, 'type' => 'int'),
array('name' => 'choice_length', 'value' => $bt_choice_length, 'type' => 'int'),
array('name' => 'bet_note', 'value' => $bt_note),
array('name' => 'bet_link_note', 'value' => $bt_link_note),
array('name' => 'bet_type_status', 'value' => $bt_status),
array('name' => 'sort_order', 'value' => $bt_sort_order, 'type' => 'int')
);
$q = $dh->sqlInsert();
mysql_query($q);
Between those those two examples you only modify one line to create editing / inserting data !
Here is the class : db-helper PHP Class
And enjoy your time !