【问题标题】:Corona SDK: Convert local Sqlite database to Json string then use Php to add to databaseCorona SDK:将本地 Sqlite 数据库转换为 Json 字符串,然后使用 Php 添加到数据库
【发布时间】:2013-10-03 15:59:40
【问题描述】:

我有一个如下所示的 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 的经验,所以我觉得很难。

谢谢!

【问题讨论】:

  • 感谢@Rob Miracle,我设法通过与我所描述的完全不同的原因来解决这个问题。一周前这些链接会很棒!反正加油。它们将来应该会派上用场!

标签: php json sqlite lua coronasdk


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-15
    • 2022-10-13
    • 2013-09-17
    • 1970-01-01
    • 2021-11-18
    • 2019-04-15
    相关资源
    最近更新 更多