Core Function MySQLConnect

From Sputnik Wiki
Jump to: navigation, search
MySQLConnect( <ip/ip:port>, <login>, <password> )

Contents

Description

Connect to a MySQL database.

Parameters

ip/ip:port

The IP example "127.0.0.1"

OR

The IP and port example "127.0.0.1:3016"

login

The MySQL login to use for the connection.

password

The MySQL password to use for the connection.

Return Value

Success: Returns the MySQL object.

Failure: Returns 0.

Remarks

Sputnik includes an easy to use built-in MySQL support since I use SQL a lot in my scripts.

Example

$CONN = MySQLConnect("127.0.0.1", "root", "777");
If($CONN)
{
	println("Connected...");
	If(MySQLSelectDB($CONN, "sp2"))
	{
		//MySQLQuery("UPDATE bla bla bla....");
		//MySQLQuery("INSERT bla bla bla....");
		println("Selected db...");
		$Data = MySQLFill($CONN, "SELECT * FROM players");
		If($Data)
		{
			println("Got data...");
			$Fields = MySQLFields($Data);
			$Rows = MySQLRows($Data);
			println("Data has '$Fields' Field(s) and '$Rows' Row(s)...");
			While( $Row = MySQLFetch($Data) )
			{
				$Name = $Row["Name"];
				$Pass = $Row["Pass"];
				println("Name '$Name' Pass '$Pass'");
			}
			//MySQLFetchReset($Data); //Uncomment if you wish to loop through this table again
		}
		Else
		{
			println("Failed to get data...");
		}
	}
	Else
	{
		println("Failed to select db...");
	}
	MySQLClose($CONN);
}
Else
{
	println("Failed to connect...");
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox