A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mariadb.com/docs/connectors/mariadb-connector-c/connect-with-mariadb-connector-c below:

Connect with MariaDB Connector/C | MariaDB Documentation

Connect with MariaDB Connector/C | MariaDB Documentation
  1. Connector/C
Connect with MariaDB Connector/C

MariaDB Connector/C enables C and C++ applications to establish client connections to MariaDB database products over TLS.

The following code demonstrates how to use MariaDB Connector/C to connect to MariaDB database products. This example uses the example database and user account:

#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>

int main (int argc, char* argv[])
{

   // Initialize Connection
   MYSQL *conn;
   if (!(conn = mysql_init(0)))
   {
      fprintf(stderr, "unable to initialize connection struct\n");
      exit(1);
   }

   // Connect to the database
   if (!mysql_real_connect(
         conn,                 // Connection
         "mariadb.example.net",// Host
         "db_user",            // User account
         "db_user_password",   // User password
         "test",               // Default database
         3306,                 // Port number
         NULL,                 // Path to socket file
         0                     // Additional options
      ))
   {
      // Report the failed-connection error & close the handle
      fprintf(stderr, "Error connecting to Server: %s\n", mysql_error(conn));
      mysql_close(conn);
      exit(1);
   }

   // Use the Connection
   // ...

   // Close the Connection
   mysql_close(conn);

   return 0;
}

This page is: Copyright © 2025 MariaDB. All rights reserved.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4