2013-06-05 74 views
0

我正在使用這一位代碼插入並從數據庫中選擇文本。我怎樣才能實現這個圖像,而不是文字。我已經完成了我的谷歌分享(ing)我找不到任何幫助。數據庫插入圖像,而不是文本

var index_count = 0 
var up_check = 0 

function get_db(a, up_check) { 
var db = LocalStorage.openDatabaseSync("DB5", "1.0", "The Example QML SQL!", 1000000); 
db.transaction(
    function(tx) { 
     tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); 
     for (var z=0; z<1000; z++){ 
      tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'Movie', z ]); 
     } 

     var rs = tx.executeSql('SELECT * FROM Greeting'); 
     var r = "" 

      for(var i = 0; i < a; i++) { 
       if (i>index_count-1 && up_check ===0) 
        r += rs.rows.item(i).salutation + ": " + rs.rows.item(i).salutee + "\t\t" 

       if (up_check === 1){ 
        var size_check =0 
        if (i >index_count-11 && size_check !==9) { 
         r += rs.rows.item(i).salutation + ": " + rs.rows.item(i).salutee + "\t\t" 
         size_check++ 
        } 
        } 
       } 

     console.log(r); 
     index_count=a; 
     return r; 
    })} 
+0

這是什麼都與MySQL呢? –

回答

1

您需要將路徑傳遞到圖像文件,作爲可存儲圖像的字段的值。你的表例如:

create table testblob (
    image_id  tinyint(3) not null default '0', 
    image   blob  not null 
); 

DB命令是:

INSERT INTO testblob (ID,IMAGE) VALUES(1,LOAD_FILE('D:/test.txt')); 

的Javascript:

ImagePath_from_MyForm = 'C:\temp\test.jpg' 
tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ z, ImagePath_from_MyForm ]); 
+0

感謝您的幫助,但我迷失在如何做到這一點 –