What is the command to create MySQL database using PHP and MySWQ?

by 2 replies
3
What is the command to create MySQL database using PHP and MySWQ?
#programming #command #create #database #mysql #myswq #php
  • The following example creates a database called "my_db":

    Code:
    <?php
     = mysql_connect("localhost","username","password");
    if (!)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    if (mysql_query("CREATE DATABASE my_db",))
      {
      echo "Database created";
      }
    else
      {
      echo "Error creating database: " . mysql_error();
      }
    
    mysql_close();
    ?>
    The logic:
    1. Connect to your database with correct host, username, and password
    2. Execute mysql query in this case is "Create database my_db"
    3. Close the mysql connection to free the resources

    You can learn more from w3schools. Hope this helps.
  • Building a Database-Driven Web Site Using PHP and MySQL- See this article that will really help you.

Next Topics on Trending Feed