Работата на Aptilis с MySQL

от MySQL UG Bulgaria

Jump to: navigation, search

Aptilis е програмен език за уеб. Повече, можете да видите тук: http://www.aptilis.com/index.html


Пример за връзка


sub mysqlConnect(mysql_host, mysql_user, mysql_pass, mysql_db)

	_MYSQL_LAST_PACKET = -1

	if instr(mysql_host$, ":") = 0
		// if no port is stated, use default port
		mysql_host = mysql_host + ":3306" $
	end if

	hdl = open("socket://" + mysql_host $)

	msg = getPacket(hdl) $

	if checkPacketError(msg$)
		return nul[]
	end if

	// Protocol version
	protoc = getCharAt(msg$, 1)

	// Client capabilities
	if protoc = 10
		clientcap = 1
	else
		clientcap = 0
	end if

	// Server version
	strend = instr(2, msg$, chr(0)$) - 2
	serverver = mid(msg$, 2, strend) $

	// Thread id
	strend = strend + 3
	// this is a 16 bit integer:
	threadid = decodeInt(mid(msg$, strend, 2)$)

	// Salt for password scrambling
	salt = mid(msg$, strend + 4, 8) $

	tmp[0] = mysql_user $
	tmp[1] = MySQLScramble(mysql_pass$, salt$, clientcap) $
	tmp[2] = mysql_db $
	loginstr = string(2,chr(0)$) + chr(1) + chr(141) + string(4,chr(0)$) + join(tmp[], chr(0)$) $
	loginstr = chr(len(loginstr$)-3) + loginstr $

	write(hdl, loginstr$)

	msg = getPacket(hdl) $

	if checkPacketError(msg$)
		return nul[]
	end if

	ret[0] = hdl
	ret[1] = threadid
	ret[2] = serverver $
	ret[3] = protoc

	return ret[]

end mysqlConnect


Ресурси

Можете да свалите цялото API за работа с MySQL от тук: http://aptilis.sourceforge.net/downloads/scripts/mysql.zip

Лични инструменти