MySQL VS INI?
#1

So, I am expierenced in web development, PHP, MySQL, CSS, JS, all that. The question I had was if MySQL just uses normal comammands like "mysql_connect();" and "mysql_fetch_assoc" blah blah...

In php, I would do the following (after connected to DB)
PHP Code:
<?php
 $info 
mysql_query("SELECT * FROM users WHERE username = '$username'");
 
$row mysql_fetch_assoc($info);
 
$money $row['money'];
 
$loc $row['loc'];
?>
ETC. and then just set those variables to the player, but obviously it is different in PAWN. Is it a lot different or kinda similar? Cause I would love to use that instead cause then I could write my own UCP.
Reply
#2

It's similar, but you can't use mysql_fetch_assoc in Pawn, for Pawn doesn't support dynamic array sizes, or named keys for that matter (enums being disregarded). Either you use the cache functions or you fetch the entire row and split it with something like sscanf.
Reply
#3

Quote:
Originally Posted by Vince
View Post
It's similar, but you can't use mysql_fetch_assoc in Pawn, for Pawn doesn't support dynamic array sizes, or named keys for that matter (enums being disregarded). Either you use the cache functions or you fetch the entire row and split it with something like sscanf.
Can you just write a small code that fetches, say, the amount of money in the %username%'s row and displaying it? Then I can use that as a refrence. Assuming that MySQL is already connected, and the table name is players
Reply
#4

This is for BlueG's plugin, R7 and above:

pawn Code:
// Somewhere
new
    mysqlquery[80];

format(mysqlquery, sizeof(mysqlquery), "SELECT id, money FROM players WHERE name = '%s'", playername);
mysql_function_query(1, mysqlquery, true, "OnPlayerDataLoad", "d", playerid);

// Somewhere else
forward OnPlayerDataLoad(playerid);
public OnPlayerDataLoad(playerid)
{
    new
        rows,
        fields;

    cache_get_data(1, rows, fields);

    if(rows)
    {
        new temp[12];
        cache_get_row(0, 0, temp); PlayerInfo[playerid][pSQLID] = strval(temp);
        cache_get_row(0, 1, temp); PlayerInfo[playerid][pMoney] = strval(temp);
    }
    return;
}
Reply
#5

[[delete]]
Reply
#6

Quote:
Originally Posted by Vince
View Post
This is for BlueG's plugin, R7 and above:

pawn Code:
// Somewhere
new
    mysqlquery[80];

format(mysqlquery, sizeof(mysqlquery), "SELECT id, money FROM players WHERE name = '%s'", playername);
mysql_function_query(1, mysqlquery, true, "OnPlayerDataLoad", "d", playerid);

// Somewhere else
forward OnPlayerDataLoad(playerid);
public OnPlayerDataLoad(playerid)
{
    new
        rows,
        fields;

    cache_get_data(1, rows, fields);

    if(rows)
    {
        new temp[12];
        cache_get_row(0, 0, temp); PlayerInfo[playerid][pSQLID] = strval(temp);
        cache_get_row(0, 1, temp); PlayerInfo[playerid][pMoney] = strval(temp);
    }
    return;
}
And how do I connect? I have the following in OnGameModeInit()
pawn Code:
mysql_debug(ENABLE_DEBUGGING);
g_ConnectionHandle = mysql_connect("host", "user", "database", "password"); //with my real info of course
and the sample gamemode shows them using "g_ConnectionHandle" infront of every query, EX: (from sample GM)
pawn Code:
new szPlayerIP[16], iNumIP, szQuery[128];
GetPlayerIp(playerid, szPlayerIP, sizeof(szPlayerIP));
iNumIP = IpToInteger(szPlayerIP);
mysql_format(g_ConnectionHandle, szQuery, "SELECT `country_code`, `country_name` FROM `ip2c` WHERE \"%d\" BETWEEN `begin_ip_num` AND `end_ip_num` LIMIT 1", iNumIP);
mysql_function_query(g_ConnectionHandle, szQuery, true, "onCountryDetect", "ds", playerid, szPlayerIP);
See how they use "g_ConnectionHandle" infront of the queries? Is that just the "mysqlquery" you used?
Reply
#7

i think sql is just shit all together plus BlueGs messed my script up -_-
Reply
#8

Quote:
Originally Posted by Yves
View Post
i think sql is just shit all together plus BlueGs messed my script up -_-
No, I think you don't use it properly.
Reply
#9

Quote:
Originally Posted by Mr_DjolE
View Post
No, I think you don't use it properly.
How do you connect to the DB using his script? I can't find it out.
Reply
#10

Quote:
Originally Posted by Nathan_Taylor
View Post
How do you connect to the DB using his script? I can't find it out.
pawn Code:
new
    connection;

Under ongamemodeinit()

connection = mysql_connect("localhost", "root", "samp", "");
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)