how can conect withe mysql c++ use clion

hello every one i am learn c++

but i have truble withe mysql
i try many sample but not work

i try used mysql
Connector/C++ 8.0.28 

but not work withe
if have good sample or small project or video to learn the
in clion
i will thanks
thanks all happy day

2 comments
Comment actions Permalink
cmake_minimum_required(VERSION 3.22)
project(appname)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(appname main.cpp)
include_directories(/usr/local/mysql/include/)
target_link_libraries(appname -L/usr/local/mysql/lib/)
SET(CMAKE_CXX_FLAGS "-lmysqlclient -lm -lz")
0
Comment actions Permalink
#include <iostream>
#include "mysql.h"

int main() {
// insert code here...
MYSQL *conn;
MYSQL_RES * res;
MYSQL_ROW row;
const char * server ="localhost";
const char *password ="11111111";
const char * user ="root";
const char *database ="test";
conn=mysql_init(NULL);


if (!mysql_real_connect(conn, server, user, password, database, 3306, NULL, 0)) {
std::cout << "لايوجد اي اتصال بقاعدة البيانات!\n" << mysql_errno(conn);
return -1;
}

std::cout << "تم الاتصال بقاعدة البيانات!\n";

if (mysql_query(conn, "SELECT * FROM phone")) {
std::cout << stderr << mysql_errno(conn);
return -1;
}
res=mysql_use_result(conn);


while ((row=mysql_fetch_row(res))!=NULL) {
std::cout <<row[0] <<"\t \t" << row[1] <<std::endl;

}
mysql_free_result(res);
mysql_close(conn);
return 0;
}
0

Please sign in to leave a comment.