FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Create mysql database using mysql command
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Create mysql database using mysql command [message #168578] Mon, 27 May 2013 10:54 Go to next message
Jack Hard is currently offline  Jack Hard
Messages: 7
Registered: December 2012
Karma: 0
Junior Member


I am having a problem when trying to create a database using mysql command. The code i am using is;

using (MySqlConnection con = connect_db())
{
con.Open();

MySqlCommand cmd = new MySqlCommand("CREATE DATABASE @name;", con);

cmd.Parameters.AddWithValue("@name", "fancydb");

try
{
cmd.ExecuteNonQuery();
}
catch (Exception exc)
{
return;
}
cmd.Dispose();
con.Close();
con.Dispose();
}

When i try to run this code i always get an error saying that i have an error in mysql syntax near "fancydb"...but when I put the name in the command like: "CREATE DATABASE facnydb;" it works. Can anyone explain to me why is the error only happening when i try and use parameters?
Re: Create mysql database using mysql command [message #186575 is a reply to message #168578] Fri, 03 October 2014 17:27 Go to previous messageGo to next message
ash is currently offline  ash
Messages: 2
Registered: October 2014
Location: nashik
Karma: 0
Junior Member
to create a database in mysql we used a command
create database database_name;

then we used that database using,
use database_name;

then create a table
create table table_name;


ASHISH DUSANE
Re: Create mysql database using mysql command [message #186576 is a reply to message #168578] Fri, 03 October 2014 17:31 Go to previous messageGo to next message
ash is currently offline  ash
Messages: 2
Registered: October 2014
Location: nashik
Karma: 0
Junior Member
we create database in mysql by using command
create database database_name;


ASHISH DUSANE
Re: Create mysql database using mysql command [message #186943 is a reply to message #186576] Tue, 04 August 2015 15:07 Go to previous message
motorinsurance16 is currently offline  motorinsurance16
Messages: 1
Registered: August 2015
Location: London
Karma: 0
Junior Member
Thats also how I create databases in my own work
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Debugging an embedded device using TCF
Next Topic: Using PHP to send mail
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Dec 27 02:12:08 GMT 2024

Total time taken to generate the page: 0.05247 seconds