function testTable() { $tb = Test::table(); $new_data = ['nickname' => 'z3']; $tb->insert($new_data); $this->assertEquals(1, $tb->count()); $this->assertEquals([['nickname' => 'z3']], $tb->selectData()); $update = $tb->update(['nickname' => 'w5']); $this->assertEquals(1, $update); $this->assertEquals([['nickname' => 'w5']], $tb->selectData()); $tb_new = clone $tb; $tb_new->where('nickname=%s', 'w5'); //$this->assertEquals('SELEC', $tb->buildSelect()); $this->assertEquals([['nickname' => 'w5']], $tb_new->selectData()); $tb_new->clearWhere(); $tb_new->andWhere(['nickname' => 'w5']); //$this->assertEquals('SELEC', $tb->buildSelect()); $this->assertEquals([['nickname' => 'w5']], $tb_new->selectData()); $this->assertEquals(1, $tb_new->update(['nickname' => 'z3'])); $this->assertEquals([['nickname' => 'z3']], $tb->selectData()); $obj_list = $tb->select(); $obj = $obj_list[0]; /* @var $obj Test */ $this->assertEquals('z3', $obj->nickname); $tb->delete(); $test = new Test(); $test->nickname = 'hehe'; $this->assertEquals(TRUE, $test->save()); $this->assertEquals('hehe', Test::table()->selectData()[0]['nickname']); $test->delete(); $this->assertEquals([], $tb->selectData()); $this->assertEquals('SELECT * FROM test Test', $tb->buildSelect()); $this->assertEquals('SELECT * FROM test Test LIMIT 10', $tb->buildSelect(10)); $this->assertEquals('SELECT * FROM test Test LIMIT 10 OFFSET 10', $tb->buildSelect(10, 10)); }
public function edit($id = 0) { $obj = new User(); $obj->get_by_id((int) $id); $testid = $this->session->userdata('testid'); $test = new Test(); $test->get_by_id($testid); if (!$_POST) { echo $obj->to_json(); } else { if (isset($_POST['model']) and $model = $_POST['model']) { $obj->from_json($model); if ($obj->save()) { $test->save($obj); //保存关系 echo $obj->to_json(); } else { echo json_encode(array('error' => $obj->error->string)); } } else { if (isset($_POST['_method']) and $_POST['_method'] === 'DELETE') { $test->delete($obj); $obj->delete(); } } } }
if (sizeof($response_data) == 0) { $response[] = array('success' => 0, 'message' => 'No Data Found'); } else { $response[] = array('success' => 1, 'data' => $response_data); } } if ($tag == 'selectJoinTest') { $table = "*"; $where = "col1=1"; $response_data = $test->select_join($table, $where); if (sizeof($response_data) == 0) { $response[] = array('success' => 0, 'message' => 'No Data Found'); } else { $response[] = array('success' => 1, 'data' => $response_data); } } if ($tag == 'deleteTest') { $id = "12"; $response_data = $test->delete($id); if (sizeof($response_data) == 0) { $response[] = array('success' => 0, 'message' => 'Operation is not successful'); } else { $response[] = array('success' => 1, 'message' => $test->table_name . ' Info Deleted'); } } } catch (Exception $ex) { $response_data[0]['success'] = 1; $response = array('posts' => $response_data); } $response = array('posts' => $response); echo json_encode($response);
<?php include '../lib/common.inc.php'; $test = new Test(); $test->id = $_REQUEST['test_id']; $test->delete();
public function delete_test($test_id) { $output = new stdClass(); $output->result = FALSE; $output->message = $this->lang->line('admin_tests_error_cant_find_test'); $this->_transaction_isolation(); $this->db->trans_begin(); $test = new Test(); $test->get_by_id(intval($test_id)); if ($test->exists()) { $test->delete(); if ($this->db->trans_status()) { $this->db->trans_commit(); $output->result = TRUE; $output->message = $this->lang->line('admin_tests_delete_test_success'); } else { $this->db->trans_rollback(); $output->message = $this->lang->line('admin_tests_error_cant_delete_test'); } } else { $this->db->trans_rollback(); } $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($output)); }