Skip to content

Mysql模块

zerlenzhang edited this page Mar 5, 2020 · 1 revision

Mysql.Connect

  • 链接数据库
  • args:
    1. 主机IP host : str
    2. 主机端口 port : int
    3. 数据库名 databaseName : str
    4. 用户名 userName : str
    5. 密码 password : str
    6. 链接回调 function(err,conn)end

Mysql.Connect(

authConfig.host,
authConfig.port,
authConfig.dbName,
authConfig.uname,
authConfig.upwd,
function ( err,conn )
	if err then
		Debug.LogError(err);
		return;
	end
	Debug.Log("connect to mysql [ auth_center_db ] success");
	mysqlConn=conn;
end);

Mysql.Query

  • 执行Sql语句

  • args:

    1. 数据库链接 conn : Connection
    2. sql语句 sql : str
    3. 执行完毕的回调 function(err,ret)end

`Mysql.Query(mysqlConn,sql,function( err,ret )

--出现错误
if err then
	if handler then
		handler(err,nil);
	end
	return;
end
--没有查到数据
if ret==nil or #ret <=0 then
	if handler then
		handler(nil,nil);
	end
	return;
end
    do_something();

end`

Mysql.Close

  • 关闭数据库
  • args:
    1. 数据库链接 conn : Connection

Mysql.Close(conn);