checkCookie(); $uid = getUid(); //获取btih,查询视频是否已经存在,如btih不存在,退出 $btih = getBtih(); //checkBtih($btih);//用不着,下面语句解决了 //查询视频是否已经存在,如btih不存在,退出 $result = NULL; //d_index出错不会有严重影响,只要更新就好 $count = safe_query("SELECT `c_index`, `dislike`, `d_index` FROM `video` WHERE `btih` = UNHEX(?);", &$result, array('s', $btih)); //http://stackoverflow.com/questions/1747894/ if ($count != 0) { die(json_err('btih_created', -1, 'Error: Video Already Exists')); } //返回空 //添加到`video` $blackhole = NULL; $count = safe_query("INSERT INTO `video` (`uid`, `time`, `view`, `reply`, `btih`, `comment`, `c_index`, `linkage`, `l_index`, `dislike`, `d_index`) \nVALUES (?, ?, 0, 0, UNHEX(?), '', '[]', '{}', '{}', '{}', '{}');", &$blackhole, array('iis', $uid, time(), $btih)); //主键自增,comment赋空字符串,其余元素赋空数组 //startup.sql有一句SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; //NO_AUTO_VALUE_ON_ZERO禁用0,但我事实上传递的是NULL(其实是没传递),可以生成下一个序列号 //为一个NOT NULL的整型赋NULL值,结果是0,它并不会出错,参见http://niutuku.com/tech/Mysql/237698.shtml //MySQL会自动将NULL值转化为该字段的默认值,哪怕是你在表定义时没有明确地为该字段设置默认值 //newCookie.php因为已经获取了最新uid所以无须担心 if ($count != 1) { die(json_err('video_notcreated', -1, 'Error: Failed to Create New Video')); } //返回空 //提高积分并暂时硬直 normalFreeze($uid, $const_PointNewVideo, $const_DelayNewVideo); //返回成功页面 exit(json_err('newVideo', 0, "Video Created Successfully!"));
} //http://stackoverflow.com/a/16308305 //var_dump($linkage_1); //echo '<br>'; //var_dump($linkage_2); //echo '<br>'; //if(count($linkage_1[$key_1])!=count($linkage_1[$key_1]))//但愿不会出现,也许这句话反而会制造麻烦 // die(json_err('link_count_not_match',-1,'Fatal Error: Link Not Match!')) $l_index_1[$key_1] = count($linkage_1[$key_1]); //这个自然是一个值,所以无所谓 $l_index_2[$key_2] = count($linkage_2[$key_2]); //这个自然是一个值,所以无所谓 //保存linkage和l_index $linkage_1 = json_encode($linkage_1); //array->json $l_index_1 = json_encode($l_index_1); //array->json $linkage_2 = json_encode($linkage_2); //array->json $l_index_2 = json_encode($l_index_2); //array->json //我没办法在这里检查update成功,但失败lib_Mysqli必然报错退出 //修改表`video`[vid,uid,btih,time,view,reply,comment,c_index,linkage,l_index,dislike,d_index] $blackhole = NULL; $count = safe_query("UPDATE `video` SET `linkage` = ?, `l_index` = ? WHERE `btih` = UNHEX(?);", &$blackhole, array('sss', $linkage_1, $l_index_1, $btih_1)); $blackhole = NULL; $count = safe_query("UPDATE `video` SET `linkage` = ?, `l_index` = ? WHERE `btih` = UNHEX(?);", &$blackhole, array('sss', $linkage_2, $l_index_2, $btih_2)); //提高积分并暂时硬直 normalFreeze($uid, $const_PointNewLink, $const_DelayNewLink); //返回成功页面 exit(json_err('newLink', 0, "Links Created Successfully!"));
} //要防止病从口入 $new_comment = json_encode($new_comment); //array->json $new_comment .= ','; //结尾添加逗号 //编辑索引[uid,time,size] $c_index = json_decode($result[0]['c_index'], true); //json->array(rather than object) //检验错误 $c_count = count($c_index); if ($result[0]['reply'] != $c_count) { die(json_err('reply_countnotmatch', -1, 'Error: Fatal Error! Counting Does not Match. Please Report to Admin!')); } if ($result[0]['LENGTH(`comment`)'] != $c_index[$c_count - 1][2]) { //$c_index[$c_count-1][2]即最后一条的size元素 die(json_err('reply_lengthnotmatch', -1, 'Error: Fatal Error! Length Does not Match. Please Report to Admin!')); } //编辑索引[uid,time,size] $c_index[] = array($uid, $the_time_now, $result[0]['LENGTH(`comment`)'] + strlen($new_comment)); $c_index = json_encode($c_index); //array->json ++$c_count; //我没办法在这里检查update成功,但失败lib_Mysqli必然报错退出 //修改表`video`[vid,uid,btih,time,view,reply,comment,c_index,linkage,l_index,dislike,d_index] $blackhole = NULL; $count = safe_query("UPDATE `video` SET `reply` = ?, `comment` = CONCAT(`comment`, ?), `c_index` = ? WHERE `btih` = UNHEX(?);", &$blackhole, array('isss', $c_count, $new_comment, $c_index, $btih)); //提高积分并暂时硬直 normalFreeze($uid, $const_PointNewComment, $const_DelayNewComment); //返回成功页面 exit(json_err('newComment', 0, "Comment Created Successfully!"));