I am newbie! I am trying to create a table on a MySQL database through php script! How would one attack this problem? What functions do I need to accomplish this? Do I need to create a database then crate a table in the data base? or do I create the database with the table all in one shot?
Do I use the query to send info to the databse?
I am using a dev server!
I am kind of lost with the basics! Where do newbies like me go and find examples of basic coding questions like his one?
create a tably in mysql through php
<?php
/ declare some relevant variables /
$DBhost = "localhost";
$DBuser = "USERNAME";
DBpass = "Password"
$DBName = "DBNAME";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
if (mysql_create_db ("NEWDB")) {
print ("Database created successfully\n");
} else {
printf ("Error creating database: %s\n", mysql_error ());
}
?>
RTFM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Read The Fucking Manuel!!!!!!!!!!!!
A friend of mine said that I would get something like, that, but when you going through the manuel and you keep on getting error messages, it gets FRUSTRATING!
Thank you Brian for answering my question!
Obvisually Bill Gates is an @!#$!
after all I a newbie, so new that I am wet behind the ears!
Thank you Brian:
I tried your code! and I had something similar to your code as well. I found an access to the database error, I think it is something to do with database it -self. Here is the error message I got with your code, which is the same with my code : Access denied for user: 'billd@localhost' to database 'NEWDB'. Any suggestions? I think it has something to do with my user rights to the database. If I get somewhere with it i'll let you know.
stupid question I know! When you create a DB with my_create_db function, are you actually creating a table with in the DB? or do you have to create a table within that DB after! the DB is created with the mysql_create_db function?.
Now I realize I am going to get flack from other people for asking such basic questions but I am 2 week year newbie and I am learning php. The only way I learn something is if I get clarity then I move on. i am not lazy and I am going to keep on plugging away at my little problems, but I thought I would try the bulletine board for the first time!I was actually looking for a forum for just newbies like myself so we can ask each other these pethetic questions! I am not a complete idiot but when your byself with a problem it is good to ehaust all your resources before going to the boss. I am a practicum student and my boss said to learn everything by myself.
Thanks again
Brian
Hi Bill,
How many people in this thread have bill as a name in one form or another ;-)
The mysql_create_db() function just creates a new database. Tables sit on the database. Imagine the 'Database' as being a filing cabinet. Then the 'tables' are the drawers in the cabinet and the 'records' are the folders in each drawer.
RTFM is a little harsh Gates, I would suggest PRTM (Please Read The Manual).
That error your getting does mean you are not allowed to access or create that database. You might need to contact your ISP and ask them for correct passwords etc.
To get a table up and running you will have to:
Connect to the database server
Create the database
Create the table.
And I would strongly suggest setting up for local development on your computer if your learning php. It might take a while to get the software up and running but it is MUCH faster in the end than having to modify a script, upload it, test it. modify it, upload it.... you see my point. To set up for local dev you'll need apache webserver http://httpd.apache.org/dist/httpd/binaries/win32/apache_1.3.20-win32-no_src-r2.msi
PHP (of course)http://php.zend.com/do_download.php?download_file=php-4.0.6-Win32.zip
and mysql http://www.mysql.com/Downloads/MySQL-3.23/mysql-3.23.41-win.zip
I also suggest the NewRiders book MySQL by Paul DuBois.
Good Luck!
I was once told that there were no stupid questions, only stupid people answering them. RTFM was a little strong.
Billy in the previous post was correct about setting up on your local machine. I do not know how strongly you feel about open source and the like, but I would consider looking at www.nusphere.com, you can download a free package which will install apache, secure apache, php, mysql, openssl, and modssl as development platform. For the newbie in all of us it is an excellent starting place.
Good luck.
John
I don't know if I agree with you in taking the easy path big johnyo. I remember the first programming language I learnt was C++. And damn me if everything else seems like a piece of cake after learning that. It may have been hard at first and taken a longer time but its done me well in the long term. I also installed apache + php raw when I first got them. If your going to be building buildings you want to understand how the foundations work if you know what I mean.
Also Nusphere costs $495 which is quite highly priced. Maybe use Nusphere to get up and running quick-smart and then work with raw apache on the side to build knowledge.
Oh yeah check out http://www.abriasoft.com/products/product16.php
for another turn-key mysql/apache/php setup that doesn't have to cost anything!
Later
Billy
Well, you can download the full install of nusphere package from www.mysql.org or www.nusphere.com for free. If you want the support package then you have to pay for it.
John