是否可以自动增加非主键?
表"book_comments"
book_id medium_int
timestamp medium_int
user_id medium_int
vote_up small_int
vote_down small_int
comment text
comment_id medium_int
Primary key -> (book_id, timestamp, user_id)
Run Code Online (Sandbox Code Playgroud)
此表上没有其他索引.但是,我想使comment_id列自动增量,以便我可以轻松地创建另一个表:
表"book_comments_votes"
comment_id (medium_int)
user_id (medium_int)
Primary key -> (comment_id, user_id)
Run Code Online (Sandbox Code Playgroud)
用户只能在每次评论时投票一次.此表通过主键强制执行此规则.
题:
是否可以自动递增非主键 - 例如,自动递增comment_id表"book_comments"中的列?
替代方案,讨论:
如上所述,我想简单地这样做.替代方案并不乐观.
book_id, timestamp, user_id.在这种情况下,我会创建一个额外的索引.book_comments_votes整个PK中的comment_id .这将超过表格的三倍.建议?思考?
// If url matches regex
$regex = "/^(/upload/temporary/)[0-9]{4}_[0-9]{2}_[0-9]{2}_[A-Za-z0-9._ /-]+.[A-z]{2,4}$/";
if (preg_match($regex, $this->value)) {
$this->valid();
}
Run Code Online (Sandbox Code Playgroud)
Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier 'p' in C:\Apache\www\profiletwist\lib\php\form\url.php on line 41
Call Stack
# Time Memory Function Location
1 0.0079 440016 {main}( ) ..\new.php:0
2 0.0964 667832 form->validate( ) ..\new.php:60
3 0.0968 668248 form_URL->validateUploadURL( ) ..\form.php:372
4 0.0969 668400 preg_match ( ) ..\url.php:41
Variables in local scope (#3)
$regex =
string '/^(/upload/temporary/)[0-9]{4}_[0-9]{2}_[0-9]{2}_[A-Za-z0-9._ /-]+.[A-z]{2,4}$/' (length=79)
Run Code Online (Sandbox Code Playgroud)
如何修复此"未知修饰符"错误的正则表达式不会发生?
最终,我想要一个正则表达式,以确保文本输入匹配:
"/upload/temporary/####_##_##_[A-z0-9 _-]+ "." [a-z]{3}
Run Code Online (Sandbox Code Playgroud)
这是文件名目标.开头不会改变,最后一部分可以是随机散列,后跟任意扩展.在正则表达式之后进行进一步处理,但这是第一次测试. …
查询构建器如何处理->first()?
它只是做一个Limit 1或是否进行一些高级检查以确定是否只返回一行?
在极少数情况下,应用程序可能希望确保仅返回1行.也许->first()不是最好的解决方案?
非常感谢任何见解或方向!