Database

There is no built-in function which can access Database in Silk. We can call the extension Dll developed with C/C++, There are  2 Dlls (SilkSQLite64.dll,SilkMySQL64.dll) which can access Sqlite and MySql accordingly.

CSqlite
We have a class named CSqlite in Silk installer, which encapsulates most of the functions in SilkSQLite64.dll and can be used easily.
#include "../include/sqlite.si"

func sqliteTest()
{
    //if SilkSQLite64.dll is not in current directory, you need to pass the path of dll here
    //db=CSqlite(sqliteDllPath);
    db=CSqlite();
    if(db.Open(db.get_curdir()+"admin.db"))
    {
        sql=sprintf("select * from user ");
        res=db.Query(sql);
        if(res)
        {
            nCount=db.RecordNum(res)+1;//the first record is field names
            nField=db.FieldNum(res);
            for(i=0;i<nCount;i++)
            {
                str="";
                for(j=0;j<nField;j++)
                {
                    value=db.GetByFieldNo(res,i,j);
                    str+=value+", ";
                }
                print(str);
            }
            db.Query_Free(res);
        }
        db.Close(); 
    }
}

CMySql
We have a class named CMySql in Silk installer, which encapsulates most of the functions SilkMySQL64.dll and can be used easily.
#include "../include/mysql.si"

func mysqlTest()
{
    //if SilkMySQL64.dll is not in current directory, you need to pass the path of dll here
    //db=CMySql(mysqlDllPath);
    db=CMySql();
    //replace with your MySQL server ip/userid/pwd/db here
    if(db.Connect("127.0.0.1","root","myroot","test_db"))
    {
        //sql=sprintf("select * from person_like where name = 'wang'");
        sql=sprintf("select * from person_like");
        res=db.Query(sql);
        if(res)
        {
            nCount=db.RecordNum(res);
            nField=db.FieldNum(res);
            for(i=0;i<nCount;i++)
            {
                str="";
                for(j=0;j<nField;j++)
                {
                    value=db.GetByFieldNo(res,i,j);
                    str+=value+", ";
                }
                print(str);
            }
            db.Query_Free(res);
        }
        db.Close(); 
    }
    
}

Please refer to the samples in installer for details.