Creating new DATABASE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • dannysheps@hotmail.com
    Second Lieutenant

    • Feb 2008
    • 138

    Creating new DATABASE

    Hello
    Im trying to install a new script on my website and this script suppose to create a new DATABASE in MySQL

    Code:
    // Connect to the MySQL server
      $link = mysql_connect("$ipmysql", "$mysqlusername", "$mysqlpassword");
      // Create a new database
      mysql_query('CREATE DATABASE phpsms');
      // Select the new database
      mysql_query('USE phpsms');
      // Create new userdata table
      mysql_query('CREATE TABLE userdata (userid VARCHAR(100), userpass VARCHAR(100), name VARCHAR(70), address VARCHAR(50), suburb VARCHAR(50), state VARCHAR(50), postcode VARCHAR(6), phone1 VARCHAR(11), phone2 VARCHAR(11), emailaddress VARCHAR(90), joineddate VARCHAR(19), ip VARCHAR(16), userno INT(11), username VARCHAR(20))');
      
      // Create new usersonline table
      mysql_query('CREATE TABLE usersonline (username VARCHAR(20))');
      // Check is there is both tables and then installation is completed
      $tablecheckuserdata = mysql_query('SELECT * FROM userdata');
      $tablecheckuserdata1 = mysql_num_rows($tablecheckuserdata);
      $tablecheckusersonline = mysql_query('SELECT * FROM usersonline');
      $tablecheckusersonline1 = mysql_num_rows($tablecheckusersonline);
      if ($tablecheckuserdata1 >= 0 && $tablecheckusersonline >= 0) {
          echo "Installation Complete!";
          mysql_close(); // Close the connection to the MySQL Server
      }
      else {
          echo "A error occured, try again";
          exit();
      }
    my question is, why i cant create a database on my own, and why always it adding my "user_name" before the database name
    e.g.
    "user_name"_DATABASE name

    Thanks

    Danny
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: Creating new DATABASE

    These are standard features of CPanel. No user has permissions to create a database through a script. You must FIRST create the database using the Cpanel facilities, then create a user (with username and password) then grant this user ALL permissions for the specific database you created, and then you should run the script modified as follows:

    // Connect to the MySQL server
    $link = mysql_connect("$ipmysql", "$mysqlusername", "$mysqlpassword");

    // Select the new database
    mysql_query('USE phpsms'); // change the part in red with the actual name of the DB you created.
    // Create new userdata table
    mysql_query('CREATE TABLE userdata (userid VARCHAR(100), userpass VARCHAR(100), name VARCHAR(70), address VARCHAR(50), suburb VARCHAR(50), state VARCHAR(50), postcode VARCHAR(6), phone1 VARCHAR(11), phone2 VARCHAR(11), emailaddress VARCHAR(90), joineddate VARCHAR(19), ip VARCHAR(16), userno INT(11), username VARCHAR(20))');

    // Create new usersonline table
    mysql_query('CREATE TABLE usersonline (username VARCHAR(20))');
    // Check is there is both tables and then installation is completed
    $tablecheckuserdata = mysql_query('SELECT * FROM userdata');
    $tablecheckuserdata1 = mysql_num_rows($tablecheckuserdata);
    $tablecheckusersonline = mysql_query('SELECT * FROM usersonline');
    $tablecheckusersonline1 = mysql_num_rows($tablecheckusersonline);
    if ($tablecheckuserdata1 >= 0 && $tablecheckusersonline >= 0) {
    echo "Installation Complete!";
    mysql_close(); // Close the connection to the MySQL Server
    }
    else {
    echo "A error occured, try again";
    exit();
    }


    Please note that you will also need to change the configuration file with the actual name of the DB, the host (localhost, that's what your $ipmysql value should be) and the actuall username and password that you created (when creating the user)
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    Working...
    X