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 )
所有这一切都是将设备的唯一ID和时间戳存储在本地sqlite数据库中。我需要获取此信息并将其放在json字符串中。我还有一个名为'testdata'的简单localhost数据库,有两列; 'id'& '时间'。我需要使用我的json字符串并使用php文件将信息插入到我的数据库中。
我没有使用php的经验所以我发现它很难。
谢谢!
答案 0 :(得分:1)
此博文可能对您有价值:
http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/
本周的Corona Geek还详细介绍了这一点: