Multi-databases access
Posted: Sat Feb 25, 2023 5:32 pm
In the same program how to access an SQLITE database and another in MYSQL (or ODBC or postgreSql)
http://www.purebasic.com
https://www.purebasic.fr/english/
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
Code: Select all
OpenDatabase( ... , #PB_Database_SQLite)
...
OpenDatabase( ... , #PB_Database_MySQL)