www.webdeveloper.com
Results 1 to 4 of 4

Thread: SQL statement that creates a new Database under phpmyadmin in MySQL

  1. #1
    Join Date
    Sep 2010
    Posts
    68

    SQL statement that creates a new Database under phpmyadmin in MySQL

    How do you write an SQL statement that creates a new Database under phpmyadmin in MySQL?

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    MySQL >= 5.0
    Code:
    CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
    (DEFAULT CHARACTER SET and COLLATE are optional)
    CREATE DATABASE syntax

  3. #3
    Join Date
    Sep 2010
    Posts
    68
    Gives error:

    #1044 - Access denied for user ''@'localhost' to database 'dbname'

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    The user MUST have a minimum privilege CREATE in order to successfully exec CREATE DATABASE command.
    Since the error states ''@'localhost' e.g. no user, I'm guessing you called it without providing a user and/or password when connecting to MySQL.
    Are you trying to execute the query in php?
    PHP Code:
    <?php
    // change username and password parameters
    $link mysqli_connect(null'username''password'null /* ignore the dbname for this instance */);

    if (
    $link === false)
        exit(
    mysqli_connect_error());
    $dbname ''// the name of the database to be created
    $result mysqli_query($link'CREATE DATABASE `' .$dbname'`');

    if (
    $result === false && !empty($error mysqli_error($link)))
        exit(
    $error);
    if ((
    $row mysqli_fetch_row($result)) !== null)
        echo 
    $row[0];
    else
        echo 
    $result;
    mysqli_close($link);
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles