Connectors

You can connect to VanadiumDB generally with all MySQL rated libraries in your programming language of your choice. The port of the database is 3306. You can change the user name and password in the settings.

PHP

mysqli::query – mysqli_query — Performs a query on the database

Change the first 4 values to connect to the database. Execute your commands with $mysqli->query("SELECT * FROM art;"). Prepared statements are currently not supported.

<?php
// Enable strict error reporting for debugging
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$host = '127.0.0.1';    // Do NOT use 'localhost' (prevents Unix socket errors)
$port = 3306;           // Replace with vanadiumdb database port
$user = 'root';         // Replace with vanadiumdb username
$pass = 'test';         // Replace with vanadiumdb password
$db   = 'default';      // Replace with vanadiumdb name

try {

    $mysqli = new mysqli($host, $user, $pass, $db, $port);

    echo "Success: Connected successfully to the custom database server on port " . $port . "!\n";
    echo "Server Version: " . $mysqli->server_info . "\n";

    echo "<table>";
    $data = $mysqli->query("SELECT * FROM art;")->fetch_all(MYSQLI_ASSOC);

    //  get header and values and printing them in the table
    $header = array_keys(reset($data));
    foreach ($header as $value) {
        echo "<td>$value</td>";
    }
    foreach ($data as $row) {
        foreach ($row as $value) {
            echo "<td>$value</td>";
        }
    }
    echo "</table>";
    // Close connection safely
    $mysqli->close();
} catch (mysqli_sql_exception $e) {
    echo "Connection Failed!\n";
    echo "Error Message: " . $e->getMessage() . "\n";
    echo "Error Code: " . $e->getCode() . "\n";
}

Run it with

php -f phpSQLExample.php 

TypeScript (Angular)

Web applications use the HTTP-REST-interface on Port 8080. You need to managed the cookie and login to recieve the data.

Create a provider api.ts file first and use withCredentials: true.

CORS is enabled by standard:

(*w).Header().Set("Access-Control-Allow-Credentials", "true")
(*w).Header().Set("Access-Control-Allow-Origin", origin)
(*w).Header().Set("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,UPDATE,OPTIONS")
(*w).Header().Set("Access-Control-Allow-Headers", "X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept")
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
    providedIn: 'root',
})
export class ApiService {

    constructor(public http: HttpClient) { }

    getHeaders() {
        return new HttpHeaders({
            "Content-Type": "application/json",
            "Accept": "application/json",
        });
    }

    get(endpoint: string) {
        return this.http.get("http://localhost:8080/"; + endpoint, { headers: this.getHeaders(), withCredentials: true },);
    }

    post(endpoint: string, body: any) {
        return this.http.post(proxyDomain + endpoint, body, {
            headers: this.getHeaders(), withCredentials: true
        });
    }
}

On your login.ts file your handle the login with the provided credentials.

this.api.post("login", { name: this.name, password: this.password }).subscribe({
    next: (result: any) => {
        console.log(result)
        this.displayTables();
        this.showModal = false;
    }, error: (error) => {
        console.log(error)
        this.loginMessage = error?.error.error
    },
});

After all, you can receive data via the route POST /query. The interface accepts a JSON with key “query” and the SQL as a value.

In this case, the typescript file loads the data in the table render “datatables.net” to display rows and columns.

import DataTable from 'datatables.net-dt';
import { ApiService } from '../services/api';
...

this.api.post("query", { query: this.stripHTML(sql) }).subscribe({
    next: (result: any) => {
            if (result.status == 200 && result.rows > 0) {

        let columns: any = []
        result.Columns.forEach((column: any) => {
        columns.push({ title: column.columName })
        });

        this.table = new DataTable('#table', {
        columns: columns, data: result.RawData

        });

        this.showTable = true;
    } else {
        this.message = result.result
        this.showTable = false;
    }
    },
    error: (error) => {
    console.error(error)
    this.message = "No connection to database - " + error.statusText;
    },
});

Python

Create a virutal environment venv if you need to install dependencies that are not global dependencies:

sudo  apt install python3.13-venv
python3 -m venv venv
cd venv
source ./bin/activate

Install the dependencies:

pip install mysql-connector-python

Create a file pythonSQLExample.py and change the parameters in the mysql.connector.connect bracket:

import mysql.connector

mydb = mysql.connector.connect(
  host="127.0.0.1",
  user="root",
  password="test",
  database="default"
)

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM art;")

myresult = mycursor.fetchall()

for x in myresult:
  print(x)

Run it with …

python3 ./pythonSQLExample.py

Golang

Update the parameters below mysql.NewConfig() and run the SQL command in db.Query("SELECT name FROM art;"). We need a struct type Art struct{} to scan the resulting rows.

package tests

import (
	"database/sql"
	"log"

	"github.com/go-sql-driver/mysql"
)

var db *sql.DB

type Art struct {
	name string
}

func main() {
	// Capture connection properties.
	cfg := mysql.NewConfig()
	cfg.User = "root"
	cfg.Passwd = "test"
	cfg.Net = "tcp"
	cfg.Addr = "127.0.0.1:3306"
	cfg.DBName = "default"

	// Get a database handle.
	var err error
	db, err = sql.Open("mysql", cfg.FormatDSN())
	if err != nil {
		log.Fatal(err)
	}

	results, err := db.Query("SELECT name FROM art;")
	if err != nil {
		panic(err.Error())
	}

	for results.Next() {
		var art Art
		// for each row, scan the result into our art composite object
		err = results.Scan(&art.name)
		if err != nil {
			panic(err.Error())
		}
		// and then print out the arts's Name attribute
		log.Println(art.name)
	}
	pingErr := db.Ping()
	if pingErr != nil {
		log.Fatal(pingErr)
	}
}

VGwort