i thought setSchema("mydatabase"); create mydatabase, but it does not.
what c++ code will create mydatabase?
everything i find, just connects to mydatabase.
Printable View
i thought setSchema("mydatabase"); create mydatabase, but it does not.
what c++ code will create mydatabase?
everything i find, just connects to mydatabase.
Again: you have to send SQL command with "CREATE DATABASE ..." to your DBMS.
See also https://www.google.com/search?q=CREA...t=gws-wiz-serp
one of the videos somehow ran, but did not have a type before function def, guessing it was suppose to be void.
const char* database = "cppdb";
conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);
but database is not created until after mysql_real_connect is called. based on function not having type before def, maybe video is missing something.
createdatabase(MYSQL* conn) is called using conn from mysql_real_connect.
001 Create a Database from the ground up in C++, is so blurry, no clue what code is, all the way to the end
answer to question is: mysql_query(conn, "CREATE DATABASE mydatabase"); , but has to have a database to create a database. mysql is there by default
#include <iostream>
#include <mysql.h>
const char* hostname = "localhost";
const char* username = "root";
const char* password = "";
const char* database = "mysql"; // has to have a database to create a database. mysql is there by default
unsigned int port = 3306;
const char* unixsocket = NULL;
unsigned long clientflag = 0;
MYSQL* connectdatabase()
{
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);
if(conn)
{
std::cout << "Connected " << conn << std::endl;
return conn;
}
else
{
std::cout << "not connected " << conn << std::endl;
return conn;
}
}
int main(int argc, char *argv[])
{
MYSQL* conn = connectdatabase();
mysql_query(conn, "CREATE DATABASE mydatabase");
return 0;
}
found
int mysql_create_db(MYSQL *mysql, const char *db)
highlights like development environment recognizes it, but is not found by compiler
You probably meant "has to have a DBMS to create a database". Didn't you?