public static function test($fpTypeID) { $ob_mapping = new Mapping(); $table_name = $ob_mapping->get_mappped_value('map_table_names', 'l_mlp_property'); $querySelect = "SELECT 1 FROM {$table_name} WHERE listingType = 'rhsProject' AND fpTypeID = {$fpTypeID} AND specialListingID = 3"; my_print($querySelect); $dbhSelect = self::$dbh->prepare($querySelect); if (!$dbhSelect) { my_print(self::$dbh->errorInfo()); die; } $dbhSelect->execute(); $ar_result = $dbhSelect->fetchAll(PDO::FETCH_ASSOC); if (count($ar_result)) { return false; } $queryInsert = "INSERT INTO {$table_name} (listingType, fpTypeID, specialListingID) VALUES ('rhsProject', {$fpTypeID}, 3)"; $dbhInsert = self::$dbh->prepare($queryInsert); if (!$dbhInsert) { my_print(self::$dbh->errorInfo()); die; } $dbhInsert->execute(); $last_id = self::$dbh->lastInsertId(); return $last_id; }
public static function get_appointment_data($table_name, $appointmentID, $column_name = NULL) { if (empty($appointmentID)) { die("The appointmentID can not be null. \n"); } if (!is_numeric($appointmentID)) { die("The appointmentID should be numeric. \n"); } $column_name = $column_name ? $column_name : 'appointmentID'; // To do - validate the $table_name $ob_mapping = new Mapping(); $data = self::get_data($ob_mapping->get_mappped_value($table_name), $column_name, $appointmentID); return $data; }
public static function get_data($table_name, $id_field = '', $id_value = '') { $ob_mapping = new Mapping(); $table_name = $ob_mapping->get_mappped_value($table_name); $query = "SELECT * FROM {$table_name} "; if ($id_field != '' && $id_value != '') { $query .= "WHERE {$id_field} = {$id_value}"; } $dbh = self::$dbh->prepare($query); if (!$dbh) { my_print(self::$dbh->errorInfo()); die; } $dbh->execute(); return $dbh->fetchAll(PDO::FETCH_ASSOC); }
public static function update_data($table, $data, $key_field) { $ar_columns = array(); $str_columns = array(); // Todo : use a validation class to get validation massages if (!is_string($table)) { die("\$table should be a string \n"); } if (!is_array($data)) { die("\$data should be an array \n"); } if (!is_string($key_field)) { die("\$key_field should be an array \n"); } if (isset($data[$key_field])) { $key_value = $data[$key_field]; unset($data[$key_field]); } else { echo "The key field <em>{$key_field}</em> is not in the data."; die; } foreach ($data as $col_name => $col_value) { $ar_columns[] = "{$col_name} = '{$col_value}'"; } $str_columns = join($ar_columns); $ob_mapping = new Mapping(); $table_name = $ob_mapping->get_mappped_value('map_table_names', $table); $query = "UPDATE {$table_name} SET {$str_columns} WHERE {$key_field} = '{$key_value}'"; $dbh = self::$dbh->prepare($query); //my_print($query); if (!$dbh) { my_print(self::$dbh->errorInfo()); die; } $dbh->execute(); $last_id = self::$dbh->lastInsertId(); return $last_id; }