getestet unter WinXP und Ubuntu 64
Code: Alles auswählen
#libmysql = 1
#MySQL_CLIENT_COMPRESS = 32 ;client_flag für Komprimierung
;dllfile.s="/usr/lib/libmysqlclient.so.16"; libpath unter Ubuntu 11.4 64
dllfile.s="libmysql.dll"
OpenLibrary(#libmysql,dllfile)
Global dbHnd.l
Prototype.i proto_mysql_init(dbHnd)
Global mysql_init.proto_mysql_init=GetFunction(#libmysql,"mysql_init")
Prototype.i proto_mysql_connect(dbHnd, host.p-ascii, user.p-ascii, passwd.p-ascii, db.p-ascii, port.l, unix_socket.p-ascii, client_flag.l)
Global mysql_real_connect.proto_mysql_connect=GetFunction(#libmysql, "mysql_real_connect")
Prototype.i proto_mysql_error(dbHnd)
Global mysql_error.proto_mysql_error=GetFunction(#libmysql,"mysql_error")
Prototype.i proto_mysql_errno(dbHnd)
Global mysql_errno.proto_mysql_errno=GetFunction(#libmysql,"mysql_errno")
Prototype.i proto_mysql_close(dbHnd)
Global mysql_close.proto_mysql_close=GetFunction(#libmysql,"mysql_close")
Prototype.i proto_mysql_query(dbHnd, sql.p-ascii,Len_sql.l)
Global mysql_real_query.proto_mysql_query=GetFunction(#libmysql, "mysql_real_query")
Prototype.i proto_mysql_use_result(dbHnd)
Global mysql_use_result.proto_mysql_use_result=GetFunction(#libmysql,"mysql_use_result")
Prototype.i proto_mysql_store_result(dbHnd)
Global mysql_store_result.proto_mysql_store_result=GetFunction(#libmysql,"mysql_store_result")
Prototype.i proto_mysql_free_result(QueryResult)
Global mysql_free_result.proto_mysql_free_result=GetFunction(#libmysql,"mysql_free_result")
Prototype.i proto_mysql_field_count(dbHnd)
Global mysql_field_count.proto_mysql_field_count=GetFunction(#libmysql,"mysql_field_count")
Prototype.i proto_mysql_fetch_row(SQLResult)
Global mysql_fetch_row.proto_mysql_fetch_row=GetFunction(#libmysql,"mysql_fetch_row")
Prototype.i proto_mysql_fetch_lengths(SQLResult)
Global mysql_fetch_lengths.proto_mysql_fetch_lengths=GetFunction(#libmysql,"mysql_fetch_lengths")
Prototype.i proto_mysql_num_rows(SQLResult)
Global mysql_num_rows.proto_mysql_num_rows=GetFunction(#libmysql,"mysql_num_rows")
Prototype.i proto_mysql_num_fields(SQLResult)
Global mysql_num_fields.proto_mysql_num_fields=GetFunction(#libmysql,"mysql_num_fields")
Prototype.i proto_mysql_insert_id(dbHnd)
Global mysql_insert_id.proto_mysql_insert_id=GetFunction(#libmysql,"mysql_insert_id")
Procedure.s mysql_get_error(db_ID.l, requester.l)
Protected Errormsg.s, i.l, Error.l
If mysql_errno(dbHnd) > 0
*Error= mysql_error(dbHnd)
Errormsg = PeekS(*Error)
If requester
Result= MessageRequester("MySQL error",Errormsg,#PB_MessageRequester_Ok)
EndIf
EndIf
ProcedureReturn Errormsg
EndProcedure
user.s = "user"
passwd.s = "passwd"
port.l = 3306 ; Default (no need to change)
host.s="192.168.????"
db.s="" ;Schema oder in SQL
requester.l=1 ;bei 1 Ausgabe der Errormeldung über Messagerequester, sonst als ergebnis der Funktion
SQL.s="SELECT * FROM XYZ " ;richtige Tabelle einsetzen
dbHnd=mysql_init(dbHnd)
Debug mysql_real_connect(dbHnd, host, user, passwd, db, port,#NULL$, #Null) ;#Null$>Verbindungsart TCP, #Null>kein Client_Flag
mysql_get_error(dbHnd, 1) ;
Result.l=mysql_real_query(dbHnd,SQL,Len(SQL))
mysql_get_error(dbHnd, 1)
If Result
Debug "Query fehlgeschlagen"
mysql_get_error(dbHnd,1)
Else
Debug "Query ok"
SQLResult=mysql_store_result.l(dbHnd)
Debug SQLResult
Debug mysql_field_count(dbHnd)
row.l= mysql_fetch_row(SQLResult)
Debug row
If row
Debug "Ergebnis vorhanden"
EndIf
Debug mysql_fetch_lengths(SQLResult)
Debug mysql_num_rows(SQLResult)
Debug mysql_num_fields(SQLResult)
mysql_free_result(SQLResult)
EndIf
mysql_close(dbHnd)
CloseLibrary(#libmysql)
End