Multi-databases access
Multi-databases access
In the same program how to access an SQLITE database and another in MYSQL (or ODBC or postgreSql)
Re: Multi-databases access
Use OpenDatabase() multiple times 

Re: Multi-databases access
No, try the code
Execute Only PART 1 -> OK
Execute Only PART 2 -> OK
Execute Both PART 1 and PART 2 -> PART 1 OK but PART 2 NOT OK
Execute Both PART 2 and PART 1 -> PART 2 OK but PART 1 NOT OK
Execute Only PART 1 -> OK
Execute Only PART 2 -> OK
Execute Both PART 1 and PART 2 -> PART 1 OK but PART 2 NOT OK
Execute Both PART 2 and PART 1 -> PART 2 OK but PART 1 NOT OK
Code: Select all
; -----------------------
;- PART 1
; -----------------------
UseSQLiteDatabase()
Filename$ = "c:\temp\bd.bdd"
If CreateFile(0, Filename$)
Debug "Fichier de base de données créé"
CloseFile(0)
If OpenDatabase(0, Filename$, "", "")
Debug "Connecté à PureBasic.sqlite"
If DatabaseUpdate(0, "CREATE TABLE info (test VARCHAR(255));")
Debug "Table créée"
CloseDatabase(0)
EndIf
EndIf
EndIf
; -----------------------
;- PART 2
; -----------------------
UseMySQLDatabase()
If OpenDatabase(9, "host=localhost port=3306 dbname=bdd", "root", "password")
Debug "Connected to MySQL"
CloseDatabase(9)
Else
Debug "Connection failed : "+DatabaseError()
EndIf
End
Re: Multi-databases access
Use the plugin parameter when you open the database:
See: https://www.purebasic.com/documentation ... abase.html
Code: Select all
OpenDatabase( ... , #PB_Database_SQLite)
...
OpenDatabase( ... , #PB_Database_MySQL)
Hygge
Re: Multi-databases access
Thanks a lot, it's ok