CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jan 2024
    Posts
    15

    [RESOLVED] how to "create" or "make" Schema

    i thought setSchema("mydatabase"); create mydatabase, but it does not.
    what c++ code will create mydatabase?
    everything i find, just connects to mydatabase.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,402

    Re: how to "create" or "make" Schema

    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    Quote Originally Posted by VictorN View Post
    create database using cpp?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,402

    Re: how to "create" or "make" Schema

    Quote Originally Posted by micha_eleric View Post
    create database using cpp?
    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
    Last edited by VictorN; February 26th, 2024 at 02:18 AM. Reason: link was added
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    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.

  6. #6
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    001 Create a Database from the ground up in C++, is so blurry, no clue what code is, all the way to the end

  7. #7
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    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;
    }
    Last edited by micha_eleric; February 28th, 2024 at 10:14 PM.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,402

    Re: how to "create" or "make" Schema

    Quote Originally Posted by micha_eleric View Post
    ... has to have a database to create a database.
    You probably meant "has to have a DBMS to create a database". Didn't you?
    Last edited by VictorN; February 29th, 2024 at 09:29 AM.
    Victor Nijegorodov

  9. #9
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    Quote Originally Posted by VictorN View Post
    You probably meant "has to have a DBMS to create a database". Didn't you?

    only if database named "mysql" is a DBMS.
    "mysql" was shown when "MariaDB [(none)]> SHOW DATABASES;"

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,402

    Re: how to "create" or "make" Schema

    Quote Originally Posted by micha_eleric View Post
    only if database named "mysql" is a DBMS.
    "mysql" was shown when "MariaDB [(none)]> SHOW DATABASES;"
    Victor Nijegorodov

  11. #11
    Join Date
    Jan 2024
    Posts
    15

    Re: how to "create" or "make" Schema

    Quote Originally Posted by VictorN View Post
    MariaDB [(none)]> SHOW DATABASES;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mydatabase |
    | mysql |
    | performance_schema |
    | sys |
    +--------------------+
    5 rows in set (0.001 sec)

  12. #12
    Join Date
    Jan 2024
    Posts
    15

    Re: [RESOLVED] how to "create" or "make" Schema

    found

    int mysql_create_db(MYSQL *mysql, const char *db)

    highlights like development environment recognizes it, but is not found by compiler

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured