Page 1 of 1

libmysql.dll MySQL

Posted: Sat Feb 26, 2005 8:19 pm
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?

Posted: Sun Feb 27, 2005 12:57 am
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!

Posted: Sun Feb 27, 2005 10:00 am
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.

Posted: Sun Feb 27, 2005 10:10 am
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]

Posted: Sun Feb 27, 2005 11:21 am
by dwfait
That part of the code is ok. "OK" gets sent to the debug log..

Posted: Sun Feb 27, 2005 12:35 pm
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.