public static function getInstance() { if (null === self::$_dbInstance) { self::$_dbInstance = new PDOAdpter(); } return self::$_dbInstance; }
public function getCourseNumberByID($id) { $request = self::$_appInstance->request(); $training_place_id = $request->get('training_place_id'); $params = array(); array_push($params, $id); array_push($params, $training_place_id); $fields = "b.id,b.number "; $sql = " SELECT {$fields} FROM student_course b "; if (isset($id)) { $sql .= " WHERE b.course_id = ? "; } if (isset($training_place_id)) { $sql .= " AND b.training_place_id = ? "; } //Fetch result into arrays $results[0] = PDOAdpter::getInstance()->select($sql, $params, false); $fields = 'count(b.id) as num '; $sql = " SELECT {$fields} FROM student_course b "; if (isset($id)) { $sql .= " WHERE b.course_id = ? "; } if (isset($training_place_id)) { $sql .= " AND b.training_place_id = ? "; } $results[1] = PDOAdpter::getInstance()->select($sql, $params, false); echo json_encode($results); }
function getAll($fileds = "*") { if (isset($this->table)) { $sql .= " select {$fileds} from " . $this->table; //Fetch result into arrays return PDOAdpter::getInstance()->select($sql, null, false); } }
public function getPositions() { $request = self::$_appInstance->request(); $fields = "*"; $sql = "SELECT {$fields} FROM position "; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, null, false); echo json_encode($results); }
private function isExist($data) { $sql = " SELECT * FROM `division_province` "; $sql .= " WHERE `division_id` = '" . $data['division_id'] . "' "; $sql .= " AND `province_id` = '" . $data['province_id'] . "' "; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, null, false); return isset($results); }
/** * Constructor * * Initialize things. * */ function __construct() { if (null == self::$_appInstance) { self::$_appInstance = Slim::getInstance(); } if (null == self::$_dbInstance) { self::$_dbInstance = PDOAdpter::getInstance(); } }
public function get($conditions, $params, $table, $bool = true) { //db table $field = $return ? '*' : 'count(id) as exist'; //Sql statement $sql = "SELECT {$field} FROM {$table} "; // if(isset()){ // } $sql .= $conditions; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, $params, false); if ($bool) { return isset($results) ? $results[0]['exist'] == 1 : false; } else { return $results; } }
public function getpeopleDetailbyID($id) { $request = self::$_appInstance->request(); $fields = "people.uno,people.id13,people.fname,people.lname,people.pos,people.qtion,people.address,"; $fields .= "people.email,people.mobile,"; $fields .= "people.pdate,YEAR(CURDATE()) - YEAR(people.pdate) - (DATE_FORMAT(CURDATE(), '%m%d') < DATE_FORMAT(people.pdate, '%m%d')) as years_of_work,"; $fields .= 'office.oname,office.ofull,'; $fields .= 'rank.rname,rank.rfull,rank.r_eng '; $sql = "SELECT {$fields} FROM {$this->table} as people "; $sql .= "join office "; $sql .= "join rank "; $sql .= "where people.oid = office.oid and people.rid = rank.rid "; $sql .= "and people.uno = '" . $id . "'"; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, null, false); if (isset($results[0])) { if ($results[0]['years_of_work'] == date("Y")) { $results[0]['years_of_work'] = "0"; } } echo json_encode($results); }
public function saveAnswer($id) { $request = self::$_appInstance->request(); $answers = $request->post('ans'); if ($answers == null) { $results['message'] = 'เกิดข้อผิดพลาด : ไม่มีข้อมูลการทำแบบทดสอบ'; $results['route'] = 'list_of_test.php'; echo json_encode($results); return; } $questions = $_SESSION['working_questions']; $data = self::processAnswer($questions, $answers); $date = new DateTime("now"); $save_data = array('total_done' => sizeof($answers), 'total_exam' => $data['total_exam'], 'score' => $data['score'], 'answers' => serialize($answers), 'exam_random_history_id' => intval($id), 'user_id' => $_SESSION['user_id'], 'datetime_end' => $date->format('Y-m-d H:i:s'), 'datetime_start' => $_SESSION['start_time']); $table = 'student_assessments'; $effected = PDOAdpter::getInstance()->insert($save_data, $table); $results = array(); if ($effected) { $results['message'] = 'ข้อมูลการทดสอบของท่านได้ถูกบันทึกไว้เรียบร้อยแล้ว'; } else { $results['message'] = 'เกิดข้อผิดพลาด : ไม่สามารถบันทึกข้อมูลได้'; } $results['route'] = 'list_of_test.php'; echo json_encode($results); }
public function isAlreadyExist($data) { //db table $table = 'student_exam_assignment'; $field = 'count(id) as valid'; //Sql statement $sql = "SELECT {$field} FROM {$table} "; /* *Treats array as a stack prevent bug&errors when binding to prepare statment *Set value by push args into stack */ $where = array(); $params = array(); //user identity criteria if (isset($data)) { array_push($where, "student_course_id = ? "); array_push($params, $data['student_course_id']); array_push($where, "exam_random_history_id = ? "); array_push($params, $data['exam_random_history_id']); array_push($where, "start_assignment = ? "); array_push($params, $data['start_assignment']); array_push($where, "end_assignment = ? "); array_push($params, $data['end_assignment']); array_push($where, "assign_by = ? "); array_push($params, $data['assign_by']); } //merge where conditions if (isset($where)) { $sql .= PDOAdpter::getInstance()->whereQuery($where); } //Fetch result into arrays $result = PDOAdpter::getInstance()->select($sql, $params, false); $valid = true; if (isset($result)) { $valid = $result[0]['valid'] > 0; } return $valid; }
function changepassword($id = null, $password = null, $newpwd = null) { if (!empty($id) && isset($id)) { $sql = "update user set password={$newpwd} where id = ? and password = ?"; $params = array(); array_push($params, $id); array_push($params, $password); $effected = PDOAdpter::getInstance()->generic($sql, $params, true); return $effected > 0; } return false; }
function changepassword($id = null, $username = null, $pwd = null) { $username = $request->post('username'); $pwd = $request->post('password'); $newpwd = $request->post('newpassword'); $user_detail = getUser(null, $username, $pwd); if (isset($user_detail)) { $sql = "update iedupoll_usr set password={$newpwd} where id = ? "; $params = array(); array_push($params, $user_detail['id']); $effected = PDOAdpter::getInstance()->generic($sql, $params, true); return $effected > 0; } return false; }
public function getSubDistrictsByID($id) { $request = self::$_appInstance->request(); $params = array(); array_push($params, $id); $fields = "*"; $sql = "SELECT {$fields} FROM districts "; if (isset($id)) { $sql .= " WHERE AMPHUR_ID = ? "; } $sql .= " ORDER BY DISTRICT_NAME"; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, $params, false); echo json_encode($results); }
public function getTotalView() { $request = self::$_appInstance->request(); $data['static_id'] = $request->get('stat_id'); $sql = " select sum(total) as totalView from statics_click "; $sql .= " WHERE `static_id` = '" . $data['static_id'] . "' "; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, null, false); echo json_encode($results); }
<?php session_start(); header("Content-type: text/xml; charset=utf-8"); require_once 'libs/PDOAdapter.php'; //include("connect.inc"); $sblid = trim($_GET['zsblid']); $i = 1; $sql = "select * from exam_group where exam_level_id='{$sblid}'"; $sbgrs = PDOAdpter::getInstance()->select($sql, null, false); $txt = "getData('ajxsb.php?zsbgid='+this.value,'tdsbid')"; echo "<select name='osbgid' onchange=" . $txt . " size='1' style='font-family: Tahoma; font-size: 16; width: 367px; color: #000 '>"; echo "<option value='0'>เลือกชื่อกลุ่มวิชา หากไม่มีกรุณาปรับปรุงชื่อกลุ่มวิชา</option>"; foreach ($sbgrs as $key => $sbgrs) { $osbgid = trim($sbgrs['id']); $osbgname = trim($sbgrs['name']); echo "<option value='" . $osbgid . "'>" . $i . " - " . $osbgname . "</option>"; $i++; } echo '</select><font color="#0000FF">'; ?>
private function isExist($data) { $sql = " SELECT * FROM `iedupoll` "; $sql .= " WHERE `first_name` LIKE '" . $data['first_name'] . "' "; $sql .= " AND `last_name` LIKE '" . $data['last_name'] . "' "; $sql .= " AND `identity` LIKE '" . $data['identity'] . "' "; $sql .= " AND `phone` LIKE '" . $data['phone'] . "' "; //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, null, false); return isset($results); }
public function getExistingExam($id, $is_error = false) { //db table $table = 'exam_random_history'; $field = ' random_questions '; //Sql statement $sql = "SELECT {$field} FROM {$table} "; /* *Treats array as a stack prevent bug&errors when binding to prepare statment *Set value by push args into stack */ $where = array(); $params = array(); //user identity criteria if (isset($id)) { //sql for pwd criteria array_push($where, "user_id = ? "); array_push($params, $id); array_push($where, "is_error = ? "); array_push($params, $is_error); } //merge where conditions if (isset($where)) { $sql .= PDOAdpter::getInstance()->whereQuery($where); } //Fetch result into arrays $result = PDOAdpter::getInstance()->select($sql, $params, false); if (isset($result)) { $results = unserialize($result[0]['random_questions']); return $results; } else { return false; } }
public function getExistingExam($id, $is_error = false) { //db table $table = '`v_exam_random_history`'; //'exam_random_history'; $field = '*'; //'id as exam_id, random_questions '; //Sql statement //$sql = "SELECT $field FROM $table "; $sql = "select `b`.`id` AS `id`,`c`.`qtn` AS `qtn`,`c`.`ans1` AS `ans1`,`c`.`ans2` AS `ans2`,`c`.`ans3` AS `ans3`,`c`.`ans4` AS `ans4`,`c`.`answer` AS `answer`,`a`.`question_id` AS `question_id`,`b`.`user_id` AS `user_id`,`b`.`name` AS `name`,`b`.`exam_minute` AS `exam_minute`,`b`.`start_date` AS `start_date`,`b`.`end_date` AS `end_date` from ((`exam_random_history_questions` `a` join `exam_random_history` `b` on((`a`.`exam_random_history_id` = `b`.`id`))) join `questions` `c` on((`a`.`question_id` = `c`.`id`)))"; /* *Treats array as a stack prevent bug&errors when binding to prepare statment *Set value by push args into stack */ $where = array(); $params = array(); //user identity criteria if (isset($id)) { //sql for pwd criteria array_push($where, "`b`.id = ? "); array_push($params, $id); } //merge where conditions if (isset($where)) { $sql .= PDOAdpter::getInstance()->whereQuery($where); } var_dump($sql); //Fetch result into arrays $results = PDOAdpter::getInstance()->select($sql, $params, false); if (isset($results)) { return $results; } else { return false; } }
<?php date_default_timezone_set('Asia/Bangkok'); //upload Btn click and post back if (isset($_POST['uploadFile'])) { //Manage CVS File $fileCSV = iconv('TIS-620', 'UTF-8', trim($_FILES['fileCSV']['name'])); $dir = "uploadFile/"; echo exec("cd.."); if (!file_exists($dir)) { echo "Cannot found {$dir}<br>"; echo "Created {$dir} ...<br>"; mkdir($dir, 0777); } $fullNameFile = "{$dir}" . "{$fileCSV}"; $pdo = PDOAdpter::getInstance(); $examID = $_SESSION['vvsbid']; //check csv if ($fileCSV != "") { if (!file_exists($fullNameFile)) { @move_uploaded_file($_FILES['fileCSV']['tmp_name'], $fullNameFile); $readFileCSV = fopen($fullNameFile, "r"); $keepday = date("Y-m-d H:i:s"); //echo "Date $keepday"; if ($readFileCSV === FALSE) { die("Error opening File : " . "{$fileCSV}"); } $date = new DateTime("now"); while (($objArr = fgetcsv($readFileCSV, 100000, ",")) !== FALSE) { //echo "SQL : $strSQL"; //$strSQL .="(`sbno` ,`apid13` ,`apdate` ,`edid13` ,`eddate` ,`qtn` ,`ans1` ,`ans2` ,`ans3` ,`ans4`) ";