0

我有一个看起来像这样的 lua 文件:

display.setStatusBar( display.HiddenStatusBar )

-- Add onscreen text
local label1 = display.newText( "SQLite demo", 20, 30, native.systemFontBold, 60 )
label1:setTextColor( 190, 190, 255 )
local label2 = display.newText( "Creates or opens a local database", 20, 100, native.systemFont, 40 )
label2:setTextColor( 190, 190, 255 )
local label3 = display.newText( "(Data is shown below)", 20, 140, native.systemFont, 40 )
label3:setTextColor( 255, 255, 190 )

--Include sqlite
require "sqlite3"
--Open data.db.  If the file doesn't exist it will be created
local path = system.pathForFile("data.db", system.DocumentsDirectory)
db = sqlite3.open( path )

--Handle the applicationExit event to close the db
local function onSystemEvent( event )
        if( event.type == "applicationExit" ) then
            db:close()
        end
end

--Setup the table if it doesn't exist
local tablesetup = [[CREATE TABLE IF NOT EXISTS test (content, content2);]]
print(tablesetup)
db:exec( tablesetup )

--Add rows with a auto index in 'id'. You don't need to specify a set of values because we're populating all of them
testvalue = {2}
local id = system.getInfo("deviceID")
testvalue[1] = id
local time_stamp = os.time()
testvalue[2] = time_stamp


local tablefill =[[INSERT INTO test VALUES (NULL, ']]..testvalue[1]..[[',']]..testvalue[2]..[['); ]]

db:exec( tablefill )


--print the sqlite version to the terminal
print( "version " .. sqlite3.version() )

--print all the table contents
for row in db:nrows("SELECT * FROM test") do
  local text = row.content.." "..row.content2
  local t = display.newText(text, 20, 160 + (60 * row.id), native.systemFont, 40)
  t:setTextColor(255,0,255)
end

--setup the system listener to catch applicationExit
Runtime:addEventListener( "system", onSystemEvent )

所有这些都是在本地 sqlite 数据库中存储设备的唯一 ID 和时间戳。我需要获取这些信息并将其放入 json 字符串中。我还有一个简单的本地主机数据库,名为“testdata”,有两列;“身份证”和“时间”。我需要获取我的 json 字符串并使用 php 文件将信息插入到我的数据库中。

我没有使用php的经验,所以我觉得很难。

谢谢!

4

1 回答 1

1

这篇博文可能对您有价值:

http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/

本周的 Corona Geek 也详细介绍了这一点:

http://www.youtube.com/watch?v=4J9A6M3Ii-A

于 2013-10-14T01:27:02.263 回答