程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> 如何將圖片存到數據庫中?

如何將圖片存到數據庫中?

編輯:關於MYSQL數據庫
如果你用的是SQL Server數據庫!你不想用後台操作你可以看看這個
下面是對text的操作你可以看看
1. 寫操作(WRITETEXT)
這裡一般要用到的函數有TextPtr獲得文本字段的指針,和TextVaild檢驗指針的有效性,@@RowCount判斷返回記錄的條數。
其基本方法是:用Textptr函數得到指針,判斷其有效性,用Writetext寫數據
函數說明:Textptr(字段名)。Writetext tablename。FIEldname @textptr(指針) [With Log] data(數據)
例如:
Begin Tran
Declare @Mytextptr VarBinary(16)
Select @mytextptr=textptr(pr_info)
From Pub_Info (updlock)
Where pud_id=’9999’
IF @Mytextptr Is Not Null
Writetext pub_info.pr_info @mytextptr with log ‘data’
Commit Tran
2. 讀操作
常用函數
PatIndex(‘%exp%’,var|fIEldname。。)
Datalength()
@@TextSize 文本大小
SettextSize N 設置文本大小
ReadText {TableName。FIEldName} {@textptr} Offet Size [HoldLock]
例如:
begin tran
Declare @mytextptr Varbinary(16),@Totalsize int,@Readsize int,@lastread int
Set textsize 100
Select @mytextptr=textptr(pr_info), @totalsize=datalength(pr_info)
@lastread=0,
@readsize= case when (textsizeeles datalength(pr_info)
end
From Pub_info
Where Pub_id=’1622’
IF @mytextptr Is not Null and @readsize>0
While (@lastread<@totalsize)
ReadText pub_info.pr_info @mytextptr @lastread @readsize holdlock
If (@@error<>0)
Break
Select @lastread=@lastread+@readsize
If ((@readsize+@lastread)>@totalsize)
Select @readsize=@totalsize-@lastread
End
Commit Tran
3.數據更新UpdateText
更新數據代替了寫操作,其基本語法是:
UpdateText Table_Name.Col_Name Text_Ptr Offest(偏移量) Deleted_Length
[With Log] [Inserted_Data|Table_Name.Scr_Column_name Str_Text_Ptr]
說明:
Offest:0說明從開頭開始,Null表示你向當前內容追加數據。
Deleted_Length:0表示不刪除任何內容,Null表示刪除所有內容。
例如1(完全代替):
Declare @mytextptr varbinary(16)
Begin tran
Select
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved