Jump to content

Switching from mysql module to dbConnect


[PXG]Blue

Recommended Posts

Hello, i'm having a problem with my Script, as i switched to a x64 server the mysql module doesnt work anymore, and i have to transform my script to dbConnect, i dont have much experience on it so i need your help here, heres the problem:

  
  
-- result is grabbed earlier with dbQuery and dbPoll 
        if(mysql_num_rows(result) > 0) then 
            local dsatz = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return tonumber(dsatz[feldname]) 
        else 
            mysql_free_result(result) 
            return false 
        end 
  
  
  

I want to convert this to dbConnect but i have no clue how :?

Thanks for your help, ^^

Link to comment
Hello, i'm having a problem with my Script, as i switched to a x64 server the mysql module doesnt work anymore, and i have to transform my script to dbConnect, i dont have much experience on it so i need your help here, heres the problem:
  
  
-- result is grabbed earlier with dbQuery and dbPoll 
        if(mysql_num_rows(result) > 0) then 
            local dsatz = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return tonumber(dsatz[feldname]) 
        else 
            mysql_free_result(result) 
            return false 
        end 
  
  
  

I want to convert this to dbConnect but i have no clue how :?

Thanks for your help, ^^

small help :P

mysql_free_result(result) = dbFree(result)

Link to comment

1LoL1 thats wrong.

mysql_free_result isnt dbFree.

The functions you want to know:

dbExec - Use it for a command where you don't need a result back (delete, update ...) - You get true or false back

dbQuery - Can use it with everything - returns a query handle which you can turn into a result (dbPoll) or free when you dont want the result (dbFree)

dbFree - Use it when you get a query handle and don't want the result

dbPoll - Use it when you get a query handle and want the result

You never use dbFree with dbPoll, always atleast one, but never both.

dbPoll returns you are result.

This result is a table.

Its index is 1 to amount of rows.

If you use WHERE name = "Bonus" and there is only 1 name="Bonus" row in db the result is like that:

result = { [1] = { column1 = value1, column2 = value2, column3 = value3 ... } } 

If there are more rows with the name "Bonus" it is like that:

result = { [1] = { column1 = value1 ... }, 
                      ... 
                      [amountrows] = { column1 = ... } } 

I always ask that way:

local result = ... 
if result and result[1] then 

So I can see if dbPoll was succesfull and there is atleast 1 row.

After that I can use a for:

for i=1, #result do 
     for column, value in pairs ( row) do 
          outputChatBox ( column .. " : "..value ) 
     end 
end 

And I've never used dbFree.

If I don't want the result I'll just use dbExec.

Link to comment

It's absolutely not the same -.-

mysql_free_result:

"Frees the last query result. This function should be called after every query, specially when these queries return any data."

dbFree:

"This function frees a database query handle. dbFree only needs to be used if a result has not been obtained with dbPoll"

You should use mysql_free_result after EVERY query!

Doesn't matter if you get any data or not.

But you use dbFree ONLY if you DON'T want to get the result.

With MySQL-module I had to use mysql_free_result every time, but with mta db functions I never used dbFree.

It's not the same, it's too different.

Link to comment
It's absolutely not the same -.-

mysql_free_result:

"Frees the last query result. This function should be called after every query, specially when these queries return any data."

dbFree:

"This function frees a database query handle. dbFree only needs to be used if a result has not been obtained with dbPoll"

You should use mysql_free_result after EVERY query!

Doesn't matter if you get any data or not.

But you use dbFree ONLY if you DON'T want to get the result.

With MySQL-module I had to use mysql_free_result every time, but with mta db functions I never used dbFree.

It's not the same, it's too different.

Totally disagree with that on so many levels. I'm a programmer for a living, using PDO, ADODB, MangoDB, RavenDB and a shit ton of other platforms for databases. You don't have to use mysql_free_result if you don't get data back, the variable is saved in your system's memory, you're cleaning this with the mysql_free_result. If you're using a delete query, no data is returned, no need to free the result. Only select queries or insert queries which returns the last ID needs a mysql_free_result. The rest is pure bullsh*t written in books which no one ever bothered to check. :lol:

The thing about the db* functions is that you can execute more than 1 query at a time and therefore MTA *might have* cleaned the result at their side already without parsing it back to the script.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...