libmysql.dll MySQL

Just starting out? Need help? Post your questions and find answers here.
dwfait
User
User
Posts: 15
Joined: Thu Mar 11, 2004 7:27 pm

libmysql.dll MySQL

Post by dwfait »

Hi, again.

Been having some trouble with using this lib..libmysql.dll..hoping someone here has experience using this.

I'm trying to get the value of ID and name from this query:

Code: Select all

      SQL = "SELECT id,name FROM ibf_members WHERE name='"+Str(Username)+"'"
However, have failed miserably. This is the code im using at the moment:

Code: Select all

      SQL = "SELECT id,name FROM ibf_members WHERE name='"+Str(Username)+"'"
      If CallFunction(#libmysql,"mysql_real_query", dbHnd, SQL, Len(SQL))
        ;GetError(dbHnd,1)
        Debug "failed"
      Else
      Debug "ok"
        *mysqlResult=CallFunction(#libmysql,"mysql_store_result",dbHnd)

         affRows   = CallFunction(#libmysql,"mysql_affected_rows",dbHnd)
          fieldNum  = CallFunction(#libmysql,"mysql_num_fields",*mysqlResult)
          rowsNum   = CallFunction(#libmysql,"mysql_num_rows",*mysqlResult)
          
          Debug affRows
          Debug fieldNum
          Debug rowsNum
          
            content.s=""

            
            ;row = 
            
            
            
            
            Debug "Field Number 1:"+Str(fieldNum)
          For i=1 To rowsNum  
            
            *mysqlRow=CallFunction(#libmysql,"mysql_fetch_row",*mysqlResult)
            *mysqlLen=CallFunction(#libmysql,"mysql_fetch_lengths",*mysqlResult)
            
            For j=1 To fieldNum
              length=PeekL(*mysqlLen+4*(j-1))
              fieldptr=PeekL(*mysqlRow+4*(j-1))
              If fieldptr>0
                content.s=PeekS(fieldptr,length)
              Else
                ;zero pointer returend means empty field
                content="NULL"
              EndIf
              ;row = row + content + ";"
              Select j
                Case 1
                  dbid.s=Str(content)
                Case 2
                  name.s=Str(content)
                EndSelect
            Next j
          Next i  

Can anyone tell me whats wrong with this code? Or possibly post some other code which achieves the same desired affect with this lib?
Why did the chicken cross the road?
Because he was on the same side as you!
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

There is quite some stuff missing in this code to make it work; mainly the function calls "mysql_init" and mysql_realconnect, but I don't know if you only didn't paste it here and actually it is existent in your code. Also you didn't say what fails; do you get an error compiling? Or does the query not happen? Or does the query give wrong/no results? Or ... ??

Just try the example from PureArea.net

http://www.purearea.net/pb/CodeArchiv/D ... Example.pb

Adapt the variables to suit your server (hostname, username, password), change the SELECT statement and it should work.

Oh, and make sure that the libmysql DLL is accessible!
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
dwfait
User
User
Posts: 15
Joined: Thu Mar 11, 2004 7:27 pm

Post by dwfait »

Sorry, should have explained more. The DLL is accessible, no errors compiling, this is only the query code. It connects without trouble, and the SQL query is correct, however, it doesnt put the expected values in the variables.
Why did the chicken cross the road?
Because he was on the same side as you!
Manolo
User
User
Posts: 75
Joined: Fri Apr 25, 2003 7:06 pm
Location: Spain

Post by Manolo »

Change this code

Code: Select all

SQL = "SELECT id,name FROM ibf_members WHERE name='"+Str(Username)+"'" 
     If CallFunction(#libmysql,"mysql_real_query", dbHnd, SQL, Len(SQL)) 
        ;GetError(dbHnd,1) 
        Debug "failed" 
      Else 
      Debug "ok" 
for this one

Code: Select all

SQL = "SELECT id,name FROM ibf_members WHERE name='"+Str(Username)+"'" 
      CallFunction(#libmysql,"mysql_real_query", dbHnd, SQL, Len(SQL)) 
        ;GetError(dbHnd,1) 
 
Regards,
Manolo[/code]
Return to the forum
dwfait
User
User
Posts: 15
Joined: Thu Mar 11, 2004 7:27 pm

Post by dwfait »

That part of the code is ok. "OK" gets sent to the debug log..
Why did the chicken cross the road?
Because he was on the same side as you!
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Maybe I find the time a bit later to put up a corresponding table on my database server; one annotation now though:

Code: Select all

SQL = "SELECT id,name FROM ibf_members WHERE name='"+Str(Username)+"'"
should be replaced with

Code: Select all

SQL = "SELECT id,name FROM ibf_members WHERE name LIKE '"+Str(Username)+"'"
because the column name contains aplhanumeric characters. The comparison is than treated a bit differently.
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
Post Reply