FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour HIX Server connect to Mariadb or Mysql
Posts: 1612
Joined: Fri Oct 07, 2005 05:56 PM

HIX Server connect to Mariadb or Mysql

Posted: Tue Aug 04, 2026 03:59 AM

Dear Carles,

How to connect to Mariadb or Mysql to fetch the data?

Thanks in advance,

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 0
Joined: Wed Aug 26, 2026 09:41 AM

Re: HIX Server connect to Mariadb or Mysql

Posted: Wed Aug 26, 2026 05:30 PM
To connect to MariaDB or MySQL from **HIX Server**, you typically use the **hbhmysql** (or **hbmysql**) RDD / SQL layer via **ADOSYS** (ADO-like layer for Harbour) or direct **SQLMIX** / **HBHMYSQL** function calls.

The standard modern approach in FiveTech environments is using **`TMySQLConnection`** (via `hbhmysql` library) or **ADOSYS** with a DSN-less connection string.

### 1. Prerequisites
* Ensure `hbhmysql.lib` (or `hbmysql.lib`) is linked in your HIX project (`.hbp` file).
* Copy `libmysql.dll` (or `libmariadb.dll`) into the same folder as your `hixserver.exe` (or system PATH).
* Add `REQUEST HBHMYSQL` (or `REQUEST HBMYSQL`) in your `main.prg` or `rddsys.prg`.

### 2. Connection Example (Direct SQL Layer / hbhmysql)

```harbour
#include "hbclass.ch"
#include "sqlmix.ch"

FUNCTION ConnectMySQL()
LOCAL oConn
LOCAL cConnString := "hbhmysql://user:pass@localhost:3306/dbname?charset=utf8mb4"

// Option A: Using SQLMIX (TMySQLConnection)
oConn := TMySQLConnection():New( cConnString )

IF oConn:IsConnected()
? "Connected OK"
// Execute queries
oConn:Execute( "SELECT VERSION()" )
// ...
oConn:Close()
ELSE
? "Error:", oConn:GetLastError()
ENDIF

RETURN oConn
```

### 3. Connection Example (ADOSYS - Recommended for portable code)

```harbour
#include "ado.ch"

FUNCTION ConnectADO()
LOCAL oConn := ADONew( "ADODB.Connection" )
LOCAL cConnStr := "DRIVER={MariaDB ODBC 3.1 Driver};SERVER=localhost;PORT=3306;DATABASE=dbname;USER=user;PASSWORD=pass;OPTION=3;CHARSET=utf8mb4;"

// Or DSN-less for MySQL native driver (if installed):
// cConnStr := "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;..."

TRY
oConn:Open( cConnStr )
? "ADO Connected OK"

// Example Query
LOCAL oRS := ADONew( "ADODB.Recordset" )
oRS:Open( "SELECT * FROM customers LIMIT 10", oConn )

WHILE !oRS:EOF
? oRS:Fields("name"):Value
oRS:MoveNext()
ENDDO
oRS:Close()

CATCH oErr
? "ADO Error:", oErr:Description
END

oConn:Close()
RETURN NIL
```

### 4. HIX Server Context (Thread Safety)
Since HIX Server is **multi-threaded** (one thread per request):
1. **Do not share a single connection object** across threads.
2. **Create the connection inside the request handler** (or use a connection pool pattern if load is high).
3. Always `oConn:Close()` (or `oConn:Destroy()`) before returning the response.

**Typical HIX Handler Structure:**

```harbour
FUNCTION MyApiHandler( oRequest, oResponse )
LOCAL oConn := ConnectMySQL() // Creates new connection per request

IF oConn != NIL .AND. oConn:IsConnected()
LOCAL aData := oConn:GetAll( "SELECT id, name FROM users" )
oResponse:SetJson( aData )
ELSE
oResponse:SetStatus( 500 )
oResponse:SetJson( { "error" : "DB Connection Failed" } )
ENDIF

IF oConn != NIL
oConn:Close()
ENDIF

RETURN .T.
```

### Summary Checklist
1. **Link library:** `hbhmysql` (native) or configure **ODBC** (ADOSYS).
2. **DLLs:** `libmariadb.dll` / `libmysql.dll` in exe folder.
3. **Charset:** Always specify `charset=utf8mb4` in connection string.
4. **Scope:** One connection per HIX request thread.

Which approach are you currently trying (Native `hbhmysql` or `ADOSYS`/ODBC)? I can detail the specific setup for that path.

Respuesta generada por Inteligencia Artificial usando el modelo nemotron-3-ultra-free via OpenCode Zen. Puede contener errores; por favor verifiquela antes de aplicar.
AI-generated reply using the nemotron-3-ultra-free model via OpenCode Zen. May contain mistakes; please verify before applying.
Posts: 1297
Joined: Fri Feb 10, 2006 02:34 PM

Re: HIX Server connect to Mariadb or Mysql

Posted: Thu Aug 27, 2026 07:04 AM

Dutch,

How are you currently connecting from Harbour?

Can you give a simple example?

C.

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 1612
Joined: Fri Oct 07, 2005 05:56 PM

Re: HIX Server connect to Mariadb or Mysql

Posted: Tue Sep 01, 2026 01:55 AM

Dear Carles,

I use FWCONNECT to connect the Mariadb server, not a pure Harbour. In previously, I use TMySqlServer() classes.

Do I need to build HIX that will support Mariadb or MySql first?
If so, How can I make it?

Carles wrote:

Dutch,

How are you currently connecting from Harbour?

Can you give a simple example?

C.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1297
Joined: Fri Feb 10, 2006 02:34 PM

Re: HIX Server connect to Mariadb or Mysql

Posted: Thu Sep 03, 2026 05:22 AM

Dutch,

Two ways to work.

  1. Download the binary from the releases section of GitHub and test if you have any standard Harbour functions to connect.

  2. If you don't have the function you're looking for (by default, the entire harbour.hbx file is loaded), download all the source code and first try compiling with the *.bat files (you'll need to adjust the paths first). If you manage to compile the server, simply add the desired source code to the hbp file and recompile.

The second method allows anyone to add functionalities they need, such as using ADS. You have access to all the source code.

Repository https://github.com/carles9000/hix

C.

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 1612
Joined: Fri Oct 07, 2005 05:56 PM

Re: HIX Server connect to Mariadb or Mysql

Posted: Wed Sep 16, 2026 01:33 PM

Deare Carles,

I can connect to Mariadb already with native TMySqlServer():New(cHost, cUser, cPassword, nPort) now.

Thank you so much,
Dutch

Carles wrote:

Dutch,

Two ways to work.

  1. Download the binary from the releases section of GitHub and test if you have any standard Harbour functions to connect.

  2. If you don't have the function you're looking for (by default, the entire harbour.hbx file is loaded), download all the source code and first try compiling with the *.bat files (you'll need to adjust the paths first). If you manage to compile the server, simply add the desired source code to the hbp file and recompile.

The second method allows anyone to add functionalities they need, such as using ADS. You have access to all the source code.

Repository https://github.com/carles9000/hix

C.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)

Continue the discussion