[SOLVED] MySQL Creating?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

[SOLVED] MySQL Creating?

Post by William »

Can anyone tell me how you can create a database with a code? Like a function? Im working an a RPG for a guy and i am new at MySQL sorry, This si probley a dumb question. And tehre really isnt a code to show you sence it is all new. And all it neads to do is get username and passwords from a database. Can anyone help me? Thanks.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Don't have the link right now but try a google search for the php db manager phpMyadmin. It's very easy to use.

However, you'll still have to figure out what column types you need and what to index - not to mention getting the privileges set up securely (allow users to connect with only the minimum privileges required).

More info on all that in the mysql manual at mysql.com.

Finally, if you're designing a database, you need to know about db normalisation and how to set up one-to-many and many-to-many relationships. Don't have my bookmarks right now or I'd give you a link to an excellent O'Reilly article on all that. Try google or pm me so I don't forget.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Thanks

Post by William »

Thanks alot :-) Ill try google haha, Its actully for a guy that wont let me into his sever fpt or nothing :oops: so im trying to make it all set up so i can do it with my PHP coding well anyways thanks alot!
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

it's actually pretty easy.

Code: Select all

<?php

//connect to mysql.   will need the server address, a username, and a password
@mysql_pconnect('server_address', 'username', 'password') or die(mysql_error());

$createdb = "CREATE Database db_name_here";
$result = mysql_query($createdb) or die(mysql_error());

mysql_select_db('db_name_here') or die(mysql_error());

$sql = "create table users(username varchar(20), pass varchar(20)";
$query = mysql_query($sql) or die(mysql_error());

?>
may want to encrypt the password though. up to you. that's just a short and simple way to do it.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Thanks

Post by William »

Thanks :)
Post Reply