Creating a database


#1

i dont understand what does goodies > mysql at the menu, do.
what is the meaning of ‘hostname’ ?
why cant i name my db ‘test’, it saying it might be taken by another user, which user is that ? besides, im the only person that has access to that page.
is this a normal database ?
why do i get an error when i try to create a simple db ?

<?php $link = mysql_connect('localhost', '',''); if (!$link) { die('Could not connect: ' . mysql_error()); } if (mysql_create_db('my_db')) { echo "Database created successfully\n"; } else { echo 'Error creating database: ' . mysql_error() . "\n"; } ?>

i’ve also tried inserting my user and password to the connection.


#2

The Machines that host mySQL host mySQL for many users. Your DB name has to be unique across all those users.

The only way to create a database is from the control panel. You cannot create it from PHP.

You cannot ever use “loacalhost” from php. You need to use your dbhost name. The databases are on different servers from your PHP/HTML.

-Jason

MP3Mystic Your personal Streaming MP3 Server
Dreamhost Hosting


#3

ti-hi(:
guess its not that bad…
but i still dont understand what i need to write in DB Hostname
will it take one of my saubdomains ? cuz thats what it looks like


#4

It might, but db host names don’t have to be human readable to a certain extent. If you make it more obsecure, then people won’t be able to brute force their way to find your databade. For example, using forums.domain.com might be asking for trouble.

And you can use localhost, depending on your hosts.It’s just that DH don’t allow you too.


#5

ok, but i still dont understand, does it take one of my subdomains ?


#6

Nope.

-Jason

MP3Mystic Your personal Streaming MP3 Server
Dreamhost Hosting


#7

k.

CREATE TABLE Person
(
LastName varchar,
FirstName varchar,
Address varchar,
Age int
)

i tried that, and got an error.
i cant create tables too ?!


#8

IIRC, varchars need a length. Try:

CREATE TABLE person (
LastName VARCHAR( 25 ),
FirstName VARCHAR( 25 ),
Address VARCHAR( 25 ),
Age INT
);

-Jason

MP3Mystic Your personal Streaming MP3 Server
Dreamhost Hosting


#9

i love you :stuck_out_tongue:


#10

do you know how do i get it in a mysql_query() command ?
i tried and i got an error that it cannot contain ‘,’ and ‘;’.
i also tried putting the command in a var:
$q = $sprintf(“CREATE TABLE person (LastName VARCHAR( 25 ),FirstName VARCHAR( 25 ),Address VARCHAR( 25 ))”)
and it didnt work.


#11

Try this:

$q = “CREATE TABLE person (LastName VARCHAR( 25 ),FirstName VARCHAR( 25 ),Address VARCHAR( 25 ))”

make sure you dont include the trailing ; and the ’ marks are optional.

-Jason

MP3Mystic Your personal Streaming MP3 Server
Dreamhost Hosting