#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    14
    Rep Power
    0
    Hello there. I'm new to MySQL, and I'm trying to use it in conjunction with PHP. However, I'm run into a stumbling block. I need to create a database and I don't have Telnet access, so I can't use any command line references.

    Basically, here's the code that I managed:

    <?php

    $connection = mysql_connect("localhost","user","pass") or die ("Couldn't connect to server.");
    $result = mysql_query("CREATE DATABASE $db_name", $connection);

    if (!$result) {
    die("Couldn't create $db_name database!");
    } else {
    echo "Database $db_name Has Been Created";
    }
    ?>

    Now I know that the connection isn't dying because the message that always appears on submittal (btw, $db_name is posted from a form), is that it couldn't create a database, not that it couldn't connect to MySQL. Help would be much appreciated.
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    61
    Try

    $result = mysql_query("CREATE DATABASE $db_name", $connection) OR die(mysql_error());

    That way you can see exactly what the MySQL error code is for that attempted query. Look at the MySQL documentation for that error code. (There is a searchable manual at www.mysql.com)

Similar Threads

  1. Wap database access
    By Efti in forum Mobile Programming
    Replies: 0
    Last Post: August 21st, 2003, 09:50 AM
  2. SQLException: Unknown database 'mysq'
    By BasilMahdi in forum MySQL Help
    Replies: 4
    Last Post: August 12th, 2003, 03:43 AM
  3. Database connectivity prob
    By Balaji Allam in forum ASP Programming
    Replies: 1
    Last Post: August 9th, 2003, 09:33 PM
  4. Validating form info before inserting it into database
    By Templhaven in forum PHP Development
    Replies: 3
    Last Post: April 24th, 2003, 10:27 PM
  5. Opinion needed on database structure
    By genedavinci in forum MySQL Help
    Replies: 2
    Last Post: March 31st, 2003, 05:24 PM

IMN logo majestic logo threadwatch logo seochat tools logo