XAMPP connection with VS2017 using C++

marcUK2

Member
Sep 23, 2019
81
68
91
Hi,

I am somewhat unsure how to proceed but have made some progress.

A while ago I downloaded XAMPP and got myself a test MySQL database up and running with Apache and phpMyAdmin etc for PHP development on localhost:3306

I now wish to access this database using C++ and VS2017 community. I downloaded and installed the mysql-for-visualstudio-1.2.9.msi

Then I downloaded both the latest 32 and 64 bit c++ Connectors 8.0.22 and extracted them to my C:MYSQL/MYSQL32 and C:MYSQL/MYSQL64. Both these folders contain includes and librarys, but I dont understand that

In VS2017, I made a new console app and managed to connect to the test database using the Server Explorer and gave my pw and login.

Im thinking that I need to do something like click on my solution and add some info in Properties/ C++/ Additional Include Directories, and then go to Linker General and assign something to Additional Library dependencies.

my #include <mysql.h> is showing error underline so my test code wont run. I cant see this header file in my connection dowload, nor does a search on the c drive reveal where it is, doesnt look like its in XAMPP anywhere.

(Im assuming that as I have XAMPP with Mysql installed and VS2017 connects to it, that I dont need to install the MySQL server from Oracle ??? - I dont want 2 different servers running on my test machine - but will this give me the include files for c++ ???)

(Ive also googled that I need to add libmysql.lib and mysqlcppconn.lib to my built folder, but I am nowhere near that stage yet.)

Any help much appreciated, this is well beyond me
 

marcUK2

Member
Sep 23, 2019
81
68
91
I've found a solution for 64bit compiles if anyone is interested / wishes to comment or advise of potential errors / improvements

I have no idea if this is technically CORRECT, but it does open my sample database I created in phpmyAdmin

I can't get the 32bit compiles to work.

On C: Drive create the following folders at root.

1.0 WMYSQL

(This can be a different path, and an environment variable path can be added
Run [Windows+R] control sysdm.cpl,,3 Then EnvironmentVariables- to simplify in MSVC).
Inside this folder create the following folders

1.1 SERVER8
1.2 CONNECTOR8SQL64
1.3 COPY-TO-RUNTIME

Alternatively link directly to the C:\ProgramFiles\MySql\connector or server folders in step 4
Download MySQL components from https://dev.mysql.com/downloads/installer/

Windows (x86, 32-bit), MSI Installer 2.5MB
Run the Installer, Select Add the following components

2.0 MySQL for Visual Studio 1.2.9 (currently) x86
2.1 MySQL Server 8.0.22 x64
2.2 Connector C++ 8.022 x64
2.3 MySQL Workbench 8.022 (optional) x64

This will download the required components

Reconfigure the server component when it has installed, give port 3307, because XAMPP will be installed on 3306. Select Development Computer for Config Type

Open the folder at C:\ProgramFiles\MySQL\Connector C++ 8.0\
3.0 Copy the [include] and [lib64] folders to [C:WMYSQL\CONNECTOR8SQL64]

Open the folder at C:\ProgramFiles\MySQL\MySQL Server 8.0\
3.1 Copy the [include] and [lib] folders to [C:WMYSQL\SERVER8]

Open the folder at C:\ProgramFiles\MySQL\Connector C++ 8.0\lib64
3.2 Copy [libcrypto-1_1-x64.dll] to [C:WMYSQL\COPY-TO-RUNTIME]
3.3 Copy [libssl-1_1-x64.dll] to [C:WMYSQL\COPY-TO-RUNTIME]

Open the folder at C:\ProgramFiles\MySQL\MySQL Server 8.0\lib
3.2 Copy [libmysql.dll] to [C:WMYSQL\COPY-TO-RUNTIME]
3.3 Copy [libmysql.lib to [C:WMYSQL\COPY-TO-RUNTIME]

4.0 Open VS2017 and create a new Console Application (or wxWIDGETS if appropriate)
4.1 Select the solutionName in the Solution Explorer and right click → Properties
4.2 Change the Configuration to All Configurations and Platform to x64
4.3 In C/C++ → General → Additional Include Directories → Edit → Add the Following
C:\WMYSQL\CONNECTOR8SQL64\include
C:\WMYSQL\SERVER8\include
Press OK

4.4 In Linker→General→Additional Library Directories → Edit → Add the Following
C:\WMYSQL\CONNECTOR8SQL64\lib64\vs14
C:\WMYSQL\SERVER8\lib
Press OK

4.5 In Linker → Input→ Additional Dependencies →Edit → Add the Following
mysqlcppconn.lib
libmysql.lib
Press OK

4.6 In VS, Select either Debug or Release and set Platform to x64
4.7 Start and Run XAMPP, Start MySQL and Start Apache (if needed)
4.8 Create a test database & table in phpmyadmin. Create some test entries
4.9 Enter the following test code in a .cpp file – (adjust variables to suit the database created)

// MySqlTest.cpp

#include <mysql.h>
#include <iostream>

int TheQueryResult;

int main()
{
MYSQL* TheConnection;
MYSQL_ROW row;
MYSQL_RES *results;
TheConnection = mysql_init(0);

TheConnection = mysql_real_connect(TheConnection, "localhost", "user", "pass", "database", 3306, NULL, 0);

if (TheConnection)
{
std::cout << "Connect to Database SUCCESS" << std::endl;
std::string sql = "SELECT * FROM articles";

//change the sql into a c style string char pointer
const char* cQuery = sql.c_str();

TheQueryResult = mysql_query(TheConnection, cQuery);

if (!TheQueryResult)
{
results = mysql_store_result(TheConnection);
while (row = mysql_fetch_row(results))
{
printf("ID: %s, SectionID: %s, VISIBLE: %s, STICKY %s, DATE %s, AUTHOR %s, REVISION %s, TITLE %s\n", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
}
}
else
{
std::cout << "Query FAILED: " << mysql_error(TheConnection) << std::endl;
}
}
else
{
std::cout << "Connect to Database FAILED" << std::endl;
}
return 0;
}


5.0 Build the project
5.1 Find the location of the project build –
(Could be C:\Users\Username\source\repos\solutionName folder by default)
5.2 Inside the [x64] folder, paste the contents of the [COPY-TO-RUNTIME] folder into the appropriate build folder (will be DEBUG or RELEASE)
5.3 The test program should now run correctly.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |