Corona SDK:将本地的Sqlite数据库转换为Json字符串,然后使用Php添加到数据库中。
2017-2-14 4:0:18
收藏:0
阅读:115
评论:1
我有一个像这样的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”,有两个列:“id”和“time”。我需要把我的JSON字符串拿出来,使用一个PHP文件把信息插入到我的数据库中。
我没有任何PHP的经验,所以我找不到办法。
谢谢!
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
这篇博客文章可能对你有价值:
http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/
此外,本周的 Corona Geek 详细介绍了这个:
http://www.youtube.com/watch?v=4J9A6M3Ii-A