unity3d sqlite

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite; // 注意:这取决于你使用的SQLite库

public class SQLiteExample : MonoBehaviour
{
    // 数据库文件路径
    private string dbPath = "URI=file:" + Application.dataPath + "/MyDatabase.db";

    void Start()
    {
        // 示例:连接数据库并创建表
        SqliteConnection conn = new SqliteConnection(dbPath);
        conn.Open();

        string createTable = "CREATE TABLE IF NOT EXISTS Players (" +
                             "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                             "name TEXT NOT NULL, " +
                             "score INTEGER)";

        SqliteCommand cmd = conn.CreateCommand();
        cmd.CommandText = createTable;
        cmd.ExecuteNonQuery();

        conn.Close();

        Debug.Log("数据库表已创建或已存在。");
    }

    // 其他数据库操作...
}

 

 

 

#############################

posted @ 2024-07-17 21:15  西北逍遥  阅读(2)  评论(0编辑  收藏  举报