鍍金池/ 問答/ 數(shù)據(jù)庫問答
話寡 回答

圖片描述

換了后是mongodb了。但是還是報(bào)錯。

安淺陌 回答

文章表:

id    name    type_id
文章id 名稱    所屬分類id

分類表:

id        name    parent_id
分類id   分類名稱    分類父級id

還有一種就是將文章中的type_id單獨(dú)拉出一張表來做關(guān)系表,類似這樣:

art_id     type_id    

個人比較推薦第二種將關(guān)系分別存儲起來,方便維護(hù)

朽鹿 回答
---模擬測試數(shù)據(jù)
;WITH test(post_no,tkt_no,[Zone],unit)AS(
   SELECT '710001','ZAA865286','A','N' UNION ALL
   SELECT '710630','ZAA865924','A','N' UNION ALL
   SELECT '710631','ZAB598749','B','N' UNION ALL
   SELECT '711261','ZAB599394','B','N' UNION ALL
   SELECT '711262','ZAC383493','C','N' UNION ALL
   SELECT '712987','ZAC385251','C','N' UNION ALL
   SELECT '720001','ZBA543954','D','C' UNION ALL
   SELECT '720407','ZBA865924','D','C' UNION ALL
   SELECT '720408','ZBB236123','E','C' UNION ALL
   SELECT '720512','ZBB236228','E','C' UNION ALL
   SELECT '720513','ZBC193757','F','C' UNION ALL
   SELECT '720645','ZBC193894','F','C'
)
/*
select min(post_no) +'~'+ max(post_no) as post_no, min(tkt_no) +char(10) + char(13) +  max(tkt_no) as tkt_no, [Zone], max(unit)
from TEST
group by zone
order by post_no
*/
select t.min_postno+1200*(sv.number-1) as StartNo,case when t.min_postno+1200*sv.number-1>=t.max_postno then t.max_postno else t.min_postno+1200*sv.number-1 end as EndNo
      ,row_number()over(order by t.groupid,sv.number) as BoxNo
      ,case when t.min_postno+1200*sv.number-1>=t.max_postno then t.max_postno else t.min_postno+1200*sv.number-1 end-(t.min_postno+1200*(sv.number-1))+1

from (
    select left(post_no,2) as groupid, min(post_no) as min_postno,max(post_no) as max_postno,CEILING((convert(int,max(post_no))-min(post_no)+1)/1200.0) as boxcount
    from test as t
    group by left(post_no,2)
) as t
inner join master.dbo.spt_values as sv on sv.type='P' and sv.number between 1 and t.boxcount
StartNo EndNo BoxNo
710001 711200 1 1200
711201 712400 2 1200
712401 712987 3 587
720001 720645 4 645
話寡 回答

在鉤子里獲取不了,受影響行是操作完mysql之后的返回結(jié)果,目前只能在鉤子外自己手動獲取到然后處理。

空白格 回答

你可以參看這個鏈接Class:

https://github.com/matyhtf/framework/blob/master/libs/Swoole/Database/MySQL.php

他的做法是每次執(zhí)行完mysql_query后即使檢測返回值,如果mysql_query返回失敗,則再執(zhí)行一次mysql_connect,這樣可以確保下一次的請求正常。

純妹 回答

數(shù)據(jù)庫中應(yīng)存儲圖片的元數(shù)據(jù),這包括上傳者、上傳時間、上傳 IP、圖片大小、圖片格式。一般還要考慮去重,即不同用戶上傳的同一張圖片在圖床上只存一份,這樣一來,圖床上的文件名應(yīng)該是圖片的 MD5/SHA1 哈希值,也要記錄在表中。如果網(wǎng)站要面向手機(jī)用戶,還要考慮在圖庫上同時存儲低質(zhì)量的圖片,這個信息也要記錄在表中。

款爺 回答

mongo 對單一文檔的寫操作總是原子的.
其實(shí)題主是想要一個權(quán)威的說法, 肯定沒有什么比官方文檔更權(quán)威了:

In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.

When a single write operation modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic and other operations may interleave.

在 mongo 中, 單個文檔的寫操作總是原子的, 即使同時更新單一文檔中的多個嵌套文檔也是如此.

當(dāng)一個操作同時更新了多個文檔的時候, 該操作對每個單一文檔的寫操作是原子的, 但整個批量更新操作并不是原子的, 其他操作有可能會被交錯執(zhí)行.

參考: mongo 官方文檔 - Atomicity and Transactions

女流氓 回答

$lookup運(yùn)算符可以做左外連接。這是MongoDB目前支持的唯一連接方式。如果你的程序里面大量需要這樣的連表,通常說明數(shù)據(jù)模型是按關(guān)系模型設(shè)計(jì)。這樣的情況要早點(diǎn)修改數(shù)據(jù)模型,否則后患無窮。
如果你去查資料可能還會查到一種DBRef。不建議使用,效率比較差,就是驅(qū)動幫你做了一次額外的查詢操作。

愿如初 回答

你用了同一個key:‘.$4’,key是標(biāo)識,不能重復(fù)

笑浮塵 回答

????事務(wù)隔離等級:

  • 未提交讀(READ UNCOMMITED) :兩個事務(wù)之間互相可見,即使另一個事務(wù)沒有提交也可以獲取數(shù)據(jù)(不推薦),這就是所謂的臟讀
  • 已提交讀(READ COMMITED):符合隔離性的基本概念,一個事務(wù)進(jìn)行時,其它已提交的事物對于該事務(wù)是可見的,即可以獲取其它事務(wù)提交的數(shù)據(jù)。
  • 可重復(fù)讀(REPEATABLE READ) :InnoDB的默認(rèn)隔離等級。事務(wù)進(jìn)行時,其它所有事務(wù)對其不可見,即多次執(zhí)行讀,得到的結(jié)果是一樣的!
  • 可串行化SERIALIZABLE): 在讀取的每一行數(shù)據(jù)上都加鎖,會造成大量的鎖超時和鎖征用,嚴(yán)格數(shù)據(jù)一致性且沒有并發(fā)是可使用。

clipboard.png

????查看系統(tǒng)的事務(wù)隔離級別:show variables like '%iso%';
????開啟一個新事務(wù):begin;
????提交一個事務(wù):commit;
????修改事物的隔離級別:set session tx_isolation='read-committed';

萌面人 回答

當(dāng)成一個普通變量導(dǎo)出引入得了。

const locals = '123';

module.exports = {
    locals: locals
};

//-------------------------------------
const app = require('./app')

console.log(app.locals)
離殤 回答

1.id 主鍵 2.user_id加索引
2.在數(shù)據(jù)表結(jié)構(gòu)優(yōu)化,增加臨時表,專門存儲兩個表的id,并將user. user_name,order.order_number存儲在臨時表內(nèi)

做不到 回答

redis正常只是做數(shù)據(jù)庫檢索結(jié)果緩存吧
你難道想直接把數(shù)據(jù)庫數(shù)據(jù)全部緩存到redis,然后用sql查詢?。。。
這不是redis干的活啊

安于心 回答

JdbcTemplateIDEA下使用的時候,有對SQL語法校驗(yàn)的功能.

淡墨 回答

根據(jù) 官方文檔中對 mongo uri 的介紹, uri 后面指定的那個 database, 是用來指定授權(quán)數(shù)據(jù)庫的, 而不是用來指定連接成功后選擇的數(shù)據(jù)庫的.

/database : Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.

之所以需要指定授權(quán)數(shù)據(jù)庫, 是因?yàn)槭跈?quán)數(shù)據(jù)庫并不總是會被起名為 admin, 這個名字只是大多數(shù)人都會起的名字, 也是 mongo 默認(rèn)會連接的授權(quán)數(shù)據(jù)庫名. 你真把授權(quán)數(shù)據(jù)庫起名成 test 也是可以的, 那連接時就需要指定授權(quán)庫為 test : mongo://user:pass@localhost:27017/test .

回到你的問題, 你的授權(quán)庫應(yīng)該不叫 phptest 吧. 把這個數(shù)據(jù)庫名去掉, 應(yīng)該就可以連接成功. 連接成功后, 再用 MongoClient 選擇庫就是了. php 的 mongo 語法還是超級簡單的:

$mongo_client->phptest
不討喜 回答

1.用max函數(shù)查詢t_order表(我加了前綴,user表也是)并根據(jù)user分組,獲取最大的time數(shù)據(jù)
2.以步驟一的結(jié)果作為查詢條件,進(jìn)行子查詢

字段名稱、表明有所調(diào)整,不要在意這些細(xì)節(jié)

select * from t_order o where EXISTS (select 1 from
(select max(t.time) tm,t.user_id uid from t_order t group by t.user_id) f
where o.time = f.tm and o.user_id = f.uid);