Skip to content

Commit dfa4766

Browse files
authored
Update README.md
1 parent 1a04d04 commit dfa4766

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

README.md

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mysql
2-
CoD4X MySQL support for GSC.
2+
CoD4X MySQL support for GSC. Continious connection up to 4 databases supported.
33

44
# Contributors
55
- [Sharpienero](https://github.com/Sharpienero/)
@@ -9,70 +9,75 @@ CoD4X MySQL support for GSC.
99
# Script Docs
1010
### MySQL Related Functions
1111

12-
#### CVARS
13-
##### `mysql_port`
14-
You can use `mysql_port` to define a default port to connect to. `mysql_real_connect` will still prioritise its own argument
15-
over the CVAR so leaving `mysql_real_connect`'s port empty will cause it to fall back to `mysql_port`. If `mysql_port` and
16-
`mysql_real_connect`'s ports are both empty then by default fall back onto mysqls default port `3306`
12+
#### `mysql_real_connect(<str host>, <str user>, <str passwd>, <str db>, [int port=3306])`
1713

18-
Usage example: `set mysql_port 3306`
14+
Connects to a database, returns handle to database connection. If you want to connect to multiple databases, you can call this function up to 4 times. Do not forget to close connection with `mysql_close()`. TODO: link here!
1915

20-
#### `mysql_real_connect()`
16+
If "localhost" passed as `host`, for *NIX OS will be changed to "127.0.0.1".
2117

22-
Connects to a database
18+
Usage example 1: `handle = mysql_real_connect("localhost", "cod4server", "12345678", "players");`
2319

24-
Usage example `db = mysql_real_connect(host, user, pass, db, *port)`
20+
Usage example 2: `handle = mysql_real_connect("255.125.255.125", "usr1337", "87654321", "stats", 1337);`
2521

26-
####### Note: *the port pram is optional
2722

28-
###### Use 127.0.0.1 on unix, and the default port for mysql is 3306.
23+
#### `mysql_close(<handle>)`
2924

30-
#### `mysql_close()`
25+
Close a MySQL connection. Handle must be valid.
3126

32-
Close a MySQL Connection
27+
Usage example: `mysql_close(handle);`
3328

34-
Usage example `mysql_close()`
29+
#### `mysql_query(<handle>, <str query>)`
3530

36-
#### `mysql_errno()`
31+
Send a query to a database and saves the result for use in following functions. Must be called after `mysql_real_connect()`.
3732

38-
Returns the MySQL Error number.
39-
Usage example: `error = mysql_errno()`
33+
Usage example: `mysql_query(handle, "SELECT * from users");`
4034

41-
#### `mysql_error()`
35+
#### `mysql_num_rows(<handle>)`
4236

43-
Returns the MySQL Error number.
44-
Usage example: `error = mysql_error()`
37+
Returns the amount of rows received after latest query. Must be called after `mysql_real_connect()` and `mysql_query()`.
4538

46-
#### `mysql_query()`
39+
Usage example: `rowsCount = mysql_num_rows(handle);`
4740

48-
Send a query to a database and returns the result for use in the following functions:
41+
#### `mysql_affected_rows(<handle>)`
4942

50-
Usage example:
51-
```cs
52-
query = mysql_query(<string query>)
53-
```
54-
55-
#### `mysql_rowcount()`
56-
Returns the amount of rows
43+
Returns the amount of affected rows after latest query. Must be called after `mysql_real_connect()` and `mysql_query()`.
5744

58-
Usage example: `count = mysql_rowcount()`
45+
Usage example: `rowsCount = mysql_affected_rows(handle);`
5946

60-
#### `mysql_affected_rows()`
61-
Returns the amount of affected rows
47+
#### `mysql_num_fields(<handle>)`
6248

63-
Usage example: `count = mysql_affected_rows()`
49+
Returns number of fields in latest query result. Must be called after `mysql_real_connect()` and `mysql_query()`.
6450

65-
#### `mysql_num_field()`
51+
Usage example: `fieldsCount = mysql_num_field(handle);`
6652

67-
Returns number of fields
53+
#### `mysql_fetch_row(<handle>)`
6854

69-
Usage example = `count = mysql_num_field()`
55+
Returns next row from latest query result as array. Array's keys are equal to column names and can be found with `getArrayKeys(<array>)`. An empty array returned if there's no more rows left. Must be called after `mysql_real_connect()` and `mysql_query()`.
7056

57+
Usage example:
58+
```
59+
arr = mysql_fetch_row(handle);
60+
keys = getArrayKeys(arr);
61+
for(j = 0; j < keys.size; j++)
62+
{
63+
iprintln("Key=" + keys[i] + ", value=" + arr[keys[i]]);
64+
}
65+
```
7166

72-
#### `mysql_fetch_rows()`
73-
74-
Fetches and handles all rows from the `mysql_query()`
67+
### Non-MySQL Related Functions
68+
#### `mysql_fetch_rows(<handle>)`
7569

76-
Usage example = `data = mysql_fetch_rows()`
70+
Returns all rows from latest query result as 2-dimensional array. Array's keys are equal to column names and can be found with `getArrayKeys(<array>)`. An empty array returned if there's no more rows left. Must be called after `mysql_real_connect()` and `mysql_query()`.
7771

78-
Returns: This function will return two different data types depending on the field count. If the field count is one, `if( mysql_num_field(mysql) == 1 )`, then the function will return a key based array `data['field_name']`. If the `mysql_num_field()` is larger than one then it will return a 2D array. The first array being a numeric array and the second being a key based array `data[0]['field_name']`.
72+
Usage example:
73+
```
74+
query = mysql_fetch_rows(handle);
75+
for(i = 0; i < query.size; i++)
76+
{
77+
keys = getArrayKeys(query[i]);
78+
for(j = 0; j < keys.size; j++)
79+
{
80+
iprintln("Row #" + i + ", Key=" + keys[i] + ", value=" + query[i][keys[i]]);
81+
}
82+
}
83+
```

0 commit comments

Comments
 (0)