} $db = Db::getInstance(); try { $db->connect(); } catch (Exception $e) { echo getJsonResponse(1, '数据库连接错误', null); Log::error_log("数据库连接错误"); exit; } if (!checkUserToken($db, $_POST['user_id'], $_POST['access_token'])) { echo getJsonResponse(2, '用户token错误', null); exit; } if ($_GET['content'] == 'username') { if (isset($_POST['user_id']) && isset($_POST['new_username'])) { $username = stringToDb($_POST['new_username']); $sql = "select user_id from users where username='******';"; $sql1 = "update users set username='******' where user_id={$_POST['user_id']};"; $res = $db->query($sql); if ($res === false) { echo getJsonResponse(1, $db->error, null); } else { if (!empty($res)) { echo getJsonResponse(3, "用户名已存在", null); } else { if ($db->execute($sql1) == false) { echo getJsonResponse(1, $db->error, null); } else { //修改成功 echo getJsonResponse(0, "修改成功", null); }
//回滚 $db->close(); Log::error_log('database error:' . "查询id出错" . ' in ' . basename(__FILE__)); exit; } if (!empty($_FILES)) { //上传文件 $config1 = array('maxSize' => 2100000, 'allowExts' => array('png', 'jpg'), 'allowTypes' => array('image/png', 'image/jpeg'), 'savePath' => '../uploads/comments/'); $up = new UploadFile($config1); for ($i = 1; $i <= 4; $i++) { $name = 'imagefile' . $i; if (isset($_FILES[$name])) { $res1 = $up->uploadOne($_FILES[$name]); if ($res1 !== false) { $savePath = 'http://' . getServerIp() . '/uploads/complaints/' . $res1['savename']; $savePath = stringToDb($savePath); if ($db->execute("insert into canteen_complaints_images values({$complaint_id},'{$savePath}');") === false) { echo getJsonResponse(1, $db->error, null); Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__)); $db->rollback(); $db->close(); exit; } } else { //上传图片失败 echo getJsonResponse(4, $uf->errorMsg, null); $db->rollback(); //回滚 $db->close(); exit; }
/** * 食物做法步骤 * @param unknown $db * @param unknown $foodid * @param unknown $content */ function setContent(&$db, $recid, $content, $imagefile) { if ($content == null) { return; } //$method=explode("||", $content); $method = json_decode($content, true); for ($i = 1; $i <= sizeof($method); $i++) { if (empty($imagefile[$i - 1])) { $imagefile[$i - 1] = 'http://' . getServerIp() . '/uploads/recommendedfood/default.jpg'; } $sql = "insert into foodmethod values({$recid},{$i},'" . stringToDb($method[$i - 1]) . "','{$imagefile[$i - 1]}');"; $res = $db->execute($sql); if (!$res) { echo getJsonResponse(1, $db->error, null); Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__)); $db->rollback(); $db->close(); exit; } } }