I had the same problem accessing an online MySQL (version 8.x) database.
To solve the problem, I use the following technique on my Mac mini M1:
First install homebrew. (
https://brew.sh)
Code: Select all
g***@mac ~ % /bin/bash -c ‘$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)’
With brew install the formula ‘mariadb-connector-c’:
Code: Select all
g***@mac ~ % brew install mariadb-connector-c
In your purebasic program, point to the installed library ‘libmariadb.dylib’ by brew. Set the environment variable ‘MARIA_PLUGIN_DIR’ to the mariadb-plugin directory.
Code: Select all
;For macOS only!
CompilerIf #PB_Compiler_Processor=#PB_Processor_Arm64
#HomebrewPath$="/opt/homebrew/"
CompilerElse
#HomebrewPath$="/usr/local/"
CompilerEndIf
SetEnvironmentVariable("MARIADB_PLUGIN_DIR",#HomebrewPath$+"lib/mariadb/plugin/")
UseMySQLDatabase(#HomebrewPath$+"lib/mariadb/libmariadb.dylib")
#Database=0
If OpenDatabase(#Database, "host=localhost port=3306 dbname='test'", "root", "")
Debug "Connected to MySQL"
DatabaseUpdate(#Database,"DROP TABLE IF EXISTS Persons")
DatabaseUpdate(#Database,"CREATE TABLE Persons (LastName varchar(255), FirstName varchar(255))")
DatabaseUpdate(#Database,~"INSERT INTO Persons (FirstName,LastName) VALUES (\"John\",\"Doe\")")
DatabaseUpdate(#Database,~"INSERT INTO Persons (FirstName,LastName) VALUES (\"Jane\",\"Smith\")")
If DatabaseQuery(#Database, "SELECT * FROM Persons")
While NextDatabaseRow(#Database)
Debug GetDatabaseString(#Database,1)+" "+GetDatabaseString(#Database,0)
Wend
FinishDatabaseQuery(#Database)
EndIf
CloseDatabase(#Database)
Else
Debug "Connection failed: "+DatabaseError()
EndIf
To test, you can install a MySQL server on your computer with ‘brew install mysql’ and create a database "test" as follows:
Code: Select all
g***@mac ~ % mysql.server start
Starting MySQL
SUCCESS!
g***@mac ~ % mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 9.0.1 Homebrew
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE test;
Query OK, 1 row affected (0,01 sec)
mysql>
If all goes well, you will get the following result when you run the purebasic program:
Connected to MySQL
John Doe
Jane Smith
To simulate the intel version (x64) on a Mac with arm64 processor, you can install the intel version of homebrew and the formula ‘mariadb-connector-c’ in the following way (Rosetta 2 must be installed):
Code: Select all
g***@mac ~ % arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
g***@mac ~ % /usr/local/bin/brew install mariadb-connector-c
Then run the program with the intel version of purebasic.