├── README.md ├── base.css ├── connetToSQL.py ├── css ├── detail.css ├── index.css ├── login_regist.css ├── question.css └── 数据库课程设计.7z /README.md: -------------------------------------------------------------------------------- 1 | ### 知乎数据库 2 | 数据库课程设计期末大作业,利用sql sever2018 进行建库,利用python处理后端程序,flask搭建前端 3 | -------------------------------------------------------------------------------- /base.css: -------------------------------------------------------------------------------- 1 | a, abbr, acronym, address, applet, article, aside, audio, b, big, blockquote, body, canvas, caption, center, cite, code, dd, del, details, dfn, div, dl, dt, em, embed, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, html, i, iframe, img, ins, kbd, label, legend, li, mark, menu, nav, object, ol, output, p, pre, q, ruby, s, samp, section, small, span, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, time, tr, tt, u, ul,li, var, video { 2 | margin: 0; 3 | padding: 0; 4 | border: 0; 5 | vertical-align: baseline; 6 | list-style: none; 7 | } 8 | 9 | 10 | .main{ 11 | background: #fff; 12 | width: 730px; 13 | overflow: hidden; 14 | margin: 0 auto; 15 | } 16 | 17 | body{ 18 | background: #f3f3f3; 19 | } 20 | 21 | .page-title{ 22 | text-align: center; 23 | padding: 20px; 24 | } -------------------------------------------------------------------------------- /connetToSQL.py: -------------------------------------------------------------------------------- 1 | import pymssql 2 | import datetime 3 | 4 | 5 | 6 | conn = pymssql.connect(host='127.0.0.1:1433', user='yhc', password='111111', database='ZhiHu', charset="UTF-8") 7 | cur = conn.cursor() 8 | 9 | def insertUser(cur,U_ID,user_name, mobile, Email,Passwd,SEX,SignDetail): 10 | sql_insert = ''' 11 | INSERT INTO user_info 12 | VALUES (%s,%s,%s,%d,%s,%s,%s,%s); 13 | ''' 14 | dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 15 | cur.execute(sql_insert, (U_ID, user_name,Passwd,mobile, Email,SEX, dt,SignDetail)) 16 | 17 | def insertQuestion(cur,Q_ID,user_ID, Q_text): 18 | sql_insert = ''' 19 | INSERT INTO question_info 20 | VALUES (%s,%s,%s,%s,%s); 21 | ''' 22 | dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 23 | cur.execute(sql_insert, (Q_ID, user_ID,Q_text, dt, 0)) 24 | 25 | def insertAnswer(cur,A_ID,Q_ID,user_ID,A_text): 26 | sql_insert = ''' 27 | INSERT INTO Answer_info 28 | VALUES (%s,%s,%s,%s,%d); 29 | ''' 30 | cur.execute(sql_insert, (A_ID,Q_ID,user_ID,A_text,0)) 31 | def insertComment(cur,C_ID,A_ID,user_ID, C_text): 32 | sql_insert = ''' 33 | INSERT INTO Comment_info 34 | VALUES (%s,%s,%s,%s); 35 | ''' 36 | cur.execute(sql_insert, (C_ID,A_ID,user_ID,C_text)) 37 | def insertCollection(cur,Q_ID,user_ID): 38 | sql_insert = ''' 39 | INSERT INTO Collection_info 40 | VALUES (%s,%s); 41 | ''' 42 | cur.execute(sql_insert, (Q_ID,user_ID)) 43 | def insertFocus(cur,Auser_ID,Buser_ID): 44 | sql_insert = ''' 45 | INSERT INTO Focus_info 46 | VALUES (%s,%s); 47 | ''' 48 | cur.execute(sql_insert, (Auser_ID,Buser_ID)) 49 | def insertAccount(cur,mobile,passwd): 50 | sql_insert = ''' 51 | INSERT INTO Account_info 52 | VALUES (%d,%s); 53 | ''' 54 | cur.execute(sql_insert, (mobile,passwd)) 55 | def selectAllUser(cur): 56 | SQL = 'select * from User_info' 57 | cur.execute(SQL) 58 | data = cur.fetchall() 59 | d = [] 60 | for i in data: 61 | d.append(list(i)) 62 | return d 63 | def selectAllQuestion(cur): 64 | SQL = 'select * from Question_info' 65 | cur.execute(SQL) 66 | data = cur.fetchall() 67 | d = [] 68 | for i in data: 69 | d.append(list(i)) 70 | return d 71 | def selectALLAnswer(cur): 72 | SQL = 'select * from Answer_info' 73 | cur.execute(SQL) 74 | data = cur.fetchall() 75 | d = [] 76 | for i in data: 77 | d.append(list(i)) 78 | return d 79 | def selectALLComment(cur): 80 | SQL = 'select * from Comment_info' 81 | cur.execute(SQL) 82 | data = cur.fetchall() 83 | d = [] 84 | for i in data: 85 | d.append(list(i)) 86 | return d 87 | def selectAnswerOfQuestion(cur,Q_ID): 88 | SQL = '''select A_text from Answer_info 89 | where Q_ID = (%s) ''' 90 | cur.execute(SQL,(Q_ID)) 91 | data = cur.fetchall() 92 | d = [] 93 | for i in data: 94 | d.append(list(i)) 95 | return d 96 | 97 | # insertAnswer(cur,'A008','Q005','u007','''看完了 @元吉 98 | # 这篇乐理错漏百出,却假装专业客观的答案,不禁捧腹大笑, 99 | # 这就是所谓的专业人士水准吗。本不想搭理,但是看到居然有这么多人将此捧为高赞, 100 | # 也无奈只能站出来,秉着知乎精神反对一下了。 101 | # ''') 102 | # insertComment(cur,'c003','A002','u006','说的真好啊啊啊啊') 103 | # insertCollection(cur,'Q001','u001') 104 | # insertFocus(cur,'u003','u006') 105 | # print('suecces') 106 | 107 | def selectUserTologin(cur,telephone,passwd): 108 | sql = ''' 109 | SELECT * FROM user_info 110 | WHERE email ='{}' and mobile = '{}' 111 | '''.format(passwd,telephone) 112 | cur.execute(sql) 113 | data = cur.fetchall() 114 | d = [] 115 | for i in data: 116 | d.append(list(i)) 117 | return d 118 | 119 | def questionAndfirstAuestion(): 120 | questions = selectAllQuestion(cur) 121 | # print(questions) 122 | # print(answers) 123 | for i in range(len(questions)): 124 | data = selectAnswerOfQuestion(cur, questions[i][0]) 125 | questions[i].append(data[0]) 126 | return questions 127 | 128 | 129 | print(selectUserTologin(cur,18801111888,'111111')) 130 | cur.close() 131 | conn.commit() 132 | conn.close() -------------------------------------------------------------------------------- /css: -------------------------------------------------------------------------------- 1 | ### 编写了一些通用的css模板 2 | -------------------------------------------------------------------------------- /detail.css: -------------------------------------------------------------------------------- 1 | .main{ 2 | padding: 20px; 3 | } 4 | 5 | .question-info{ 6 | text-align: center; 7 | } 8 | 9 | .comment-group-title{ 10 | margin-top: 20px; 11 | } 12 | 13 | .form-container{ 14 | width: 500px; 15 | margin-top: 10px; 16 | text-align: right; 17 | } 18 | 19 | .comment-group li{ 20 | border-bottom:1px solid #eee; 21 | padding: 10px 0; 22 | } 23 | 24 | .comment-group li .user-info{ 25 | height: 40px; 26 | line-height:40px; 27 | color: #9b9b9b; 28 | font-size: 16px; 29 | } 30 | 31 | .user-info .avatar{ 32 | height:40px; 33 | width: 40px; 34 | float: left; 35 | border-radius: 50%; 36 | } 37 | 38 | .user-info .username{ 39 | margin-left: 10px; 40 | } 41 | .user-info .create-time{ 42 | float: right; 43 | } 44 | .comment-content{ 45 | margin-left: 50px; 46 | } 47 | -------------------------------------------------------------------------------- /index.css: -------------------------------------------------------------------------------- 1 | .main{ 2 | border: 1px solid #e6e6e6; 3 | } 4 | 5 | .main .question-ul{ 6 | } 7 | 8 | .question-ul li{ 9 | padding: 10px; 10 | overflow: hidden; 11 | border-bottom:1px solid #eee; 12 | } 13 | .side-question{ 14 | float: left; 15 | height:100%; 16 | } 17 | .side-question-avatar{ 18 | width: 38px; 19 | height:38px; 20 | border-radius: 3px; 21 | } 22 | 23 | .question-main{ 24 | float: left; 25 | width: 660px; 26 | margin-left:10px; 27 | overflow: hidden; 28 | } 29 | 30 | .question-title a{ 31 | color: #259; 32 | font-size:20px; 33 | font-weight: 900; 34 | } 35 | .question-author{ 36 | font-size: 12px; 37 | margin-top: 5px; 38 | } 39 | .question-content{ 40 | margin-top: 5px; 41 | font-size:12px; 42 | } 43 | .question-detail{ 44 | text-align: right; 45 | margin-top: 10px; 46 | } 47 | .question-detail .question-author{ 48 | margin-right:10px; 49 | } -------------------------------------------------------------------------------- /login_regist.css: -------------------------------------------------------------------------------- 1 | .form-container{ 2 | width: 300px; 3 | margin: 0 auto; 4 | } -------------------------------------------------------------------------------- /question.css: -------------------------------------------------------------------------------- 1 | .form-container{ 2 | width: 500px; 3 | margin: 0 auto; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /数据库课程设计.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neoyanghc/zhihu_database_flask/d185e53fbea47dcdf507b40d99d97bee0cb6bb25/数据库课程设计.7z --------------------------------------------------------------------------------