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
Return to the default flat view Create a new topic Submit Reply
Create mysql database using mysql command [message #168578] Mon, 27 May 2013 10:54 Go to previous message
Jack Hard is currently offline  Jack Hard
Messages: 7
Registered: December 2012
Karma:
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?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
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: Mon Apr 29 05:35:48 GMT 2024

Total time taken to generate the page: 0.02988 seconds