Multi-databases access

Just starting out? Need help? Post your questions and find answers here.
al2791
User
User
Posts: 20
Joined: Mon Oct 23, 2017 7:28 am

Multi-databases access

Post by al2791 »

In the same program how to access an SQLITE database and another in MYSQL (or ODBC or postgreSql)
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Multi-databases access

Post by infratec »

Use OpenDatabase() multiple times :wink:
al2791
User
User
Posts: 20
Joined: Mon Oct 23, 2017 7:28 am

Re: Multi-databases access

Post by al2791 »

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

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
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Multi-databases access

Post by Kiffi »

Use the plugin parameter when you open the database:

Code: Select all

OpenDatabase( ... , #PB_Database_SQLite)
...
OpenDatabase( ... , #PB_Database_MySQL)
See: https://www.purebasic.com/documentation ... abase.html
Hygge
al2791
User
User
Posts: 20
Joined: Mon Oct 23, 2017 7:28 am

Re: Multi-databases access

Post by al2791 »

Thanks a lot, it's ok
Post Reply