What Happens If You Do Not Have Privileges to Create Database

Q

What Happens If You Do Not Have Privileges to Create Database? - MySQL FAQs - PHP Connections and Query Execution

✍: FYIcenter.com

A

If your MySQL server is provided by your Internet service company, your user account will most likely have no privilege to create new databases on the server. In that case, your CREATE DATABASE statement will fail. Here is an example of using a less privileged user account to create a new database:

<?php
  $con = mysql_connect('localhost:8888', 'guest', 'pub');
  $sql = 'CREATE DATABASE fyicenter';
  if (mysql_query($sql, $con)) {
    print("Database fyi created.\n");
  } else {
    print("Database creation failed.\n");
  }
  mysql_close($con); 
?>

If you run this script, you will get something like this:

Database creation failed.

2007-05-10, 4958👍, 0💬