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

Home » General » PHP discussions » Create mysql database using mysql command
Show: Today's Messages :: Unread Messages :: Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
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 06:54 Go to next message
Jack Hard is currently offline  Jack Hard
Messages: 7
Registered: December 2012
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user


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?
Message by ash is ignored  [reveal message]  [reveal all messages by ash]  [stop ignoring this user] Go to previous messageGo to next message
Message by ash is ignored  [reveal message]  [reveal all messages by ash]  [stop ignoring this user] Go to previous messageGo to next message
Re: Create mysql database using mysql command [message #186943 is a reply to message #186576] Tue, 04 August 2015 11:07 Go to previous message
motorinsurance16 is currently offline  motorinsurance16
Messages: 1
Registered: August 2015
Location: London
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Thats also how I create databases in my own work
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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 Jul 10 02:31:00 EDT 2020

Total time taken to generate the page: 0.01597 seconds