一般很少將二進(jìn)制的數(shù)據(jù),存到數(shù)據(jù)庫里一般是加二年制的數(shù)據(jù)轉(zhuǎn)換成指定的文件保存在,嗯文件目錄里然后再,數(shù)據(jù)庫里存儲(chǔ)對(duì)應(yīng)的存儲(chǔ)地址,或者是,蔣,數(shù)據(jù)轉(zhuǎn)換成其他類型存入到數(shù)據(jù)庫。
在循化等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作專業(yè)公司,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營(yíng)銷,外貿(mào)網(wǎng)站建設(shè),循化網(wǎng)站建設(shè)費(fèi)用合理。
用ADO方式連的MYSQL, 已經(jīng)用AppendChunk圖片以二進(jìn)制插入數(shù)據(jù)庫中,下面是讀取的不分,寫入相反的方式
void DatabaseFile::GetImage()
{
_RecordsetPtr pRs = NULL;
pRs.CreateInstance(__uuidof(Recordset));
_variant_t varChunk;
_variant_t varBLOB;
try
{
CString sql = "select image from visdata where DetectTime = '2008-06-19 11:23:44';";
//Open a Recordset
HRESULT hr = pRs-Open(_variant_t("select * from visdata;"),_variant_t((IDispatch *) m_pConnection,true),adOpenKeyset,adLockOptimistic,adCmdText);
//read data
long lDataLength = pRs-Fields-GetItem("image")-ActualSize;//數(shù)據(jù)長(zhǎng)度可以正確獲取
varBLOB = pRs-GetFields()-GetItem("image")-GetChunk(lDataLength);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
BYTE *pBuf = NULL;
pBuf = (BYTE*)GlobalAlloc(GMEM_FIXED,lDataLength);//分配空間
hr = SafeArrayAccessData(varBLOB.parray,(void **)pBuf);
if (FAILED(hr))
return;
//Build a File
char tmpPath[_MAX_PATH+1];
GetCurrentDirectory( MAX_PATH,tmpPath);
CString strFileName = "\\temp2.bmp";//輸出圖片的文件名
strFileName = tmpPath+strFileName;
CFile outFile(strFileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary );
/*要判斷文件是否創(chuàng)建成功*/
LPSTR buffer = (LPSTR)GlobalLock((HGLOBAL)(pBuf));
outFile.WriteHuge(buffer,lDataLength);
GlobalUnlock((HGLOBAL)pBuf);
outFile.Close();
SafeArrayUnaccessData (varBLOB.parray);
}
pRs-Close();
}
這有什么難的嗎?
你把你的二進(jìn)制數(shù)據(jù)可以轉(zhuǎn)成文本串插入,就跟普通的插入一樣啊。
import MySQLdb, cPickle
# Connect to a DB, e.g., the test DB on your localhost, and get a cursor
connection = MySQLdb.connect(db="test")
cursor = connection.cursor( )
# Make a new table for experimentation
cursor.execute("CREATE TABLE justatest (name TEXT, ablob BLOB)")
try:
# Prepare some BLOBs to insert in the table
names = 'aramis', 'athos', 'porthos'
data = { }
for name in names:
datum = list(name)
datum.sort( )
data[name] = cPickle.dumps(datum, 2)
# Perform the insertions
sql = "INSERT INTO justatest VALUES(%s, %s)"
for name in names:
cursor.execute(sql, (name, MySQLdb.escape_string(data[name])) )
# Recover the data so you can check back
sql = "SELECT name, ablob FROM justatest ORDER BY name"
cursor.execute(sql)
for name, blob in cursor.fetchall( ):
print name, cPickle.loads(blob), cPickle.loads(data[name])
finally:
# Done. Remove the table and close the connection.
cursor.execute("DROP TABLE justatest")
connection.close( )
二進(jìn)制文件大的話,建議使用保存文件名(含路徑)的方法!
文件小的話,用text即可,將二進(jìn)制轉(zhuǎn)換成16進(jìn)制形式,讀的時(shí)候再轉(zhuǎn)換回去
本文題目:mysql二進(jìn)制怎么插入 mysql二進(jìn)制安裝教程
轉(zhuǎn)載來于:http://jinyejixie.com/article32/docjhsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站內(nèi)鏈、ChatGPT、網(wǎng)站策劃、搜索引擎優(yōu)化、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)