Forum Moderators: coopster

Message Too Old, No Replies

DB - Create, Connect, Write to (a database)

working with larry ullmans examples...

         

JAB Creations

5:05 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$frustration, $random_curses

Ok, now that is behind me... I'm trying to learn how to create, connect, and write to a database.

I have some very basic questions to start out with...

One, I have Cpanel and I can create databases, create users, and then associate users to that database.

Can I assume I can create a database and associate a user through *just* php? I'm learning from Larry Ullman's php book but its giving me errors! :-(

---

Here is one attempt...
Conditions - No database created or anything with cpanel, trying to avoid cpanel!

*PHP code*
<?php
$Link=mysql_connect("localhost","john1","john1");
mysql_create_db("john1".$Link);
?>
**

Results..
**
Warning: mysql_connect(): Access denied for user: 'john1@localhost' (Using password: YES) in /home/jabcreat/public_html/database.php on line 2

Fatal error: Call to undefined function: mysql_create_db() in /home/jabcreat/public_html/database.php on line 3
**

Anyway I'll just start out with that.

JAB Creations

5:15 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh yeah, my server with cpanel likes to make all my stuff start with...

jabcreat_

I can understand for shared hosting...or not...whatever...

I don't know how this effects stuff but I'm pretty sure it does!

mincklerstraat

7:27 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To connect to the db in the first place, of course, you need a valid username and password to connect to the db server.

It's likely that your host would place restrictions on the database user you have so you can't create databases.

Don't go experimenting too much on your host; instead, visit apachefriends.org and download a php/mysql server combo on your local box, and play around with that. Much smaller chance of pissing off your host. Once you get good, nice, stable code, test that on your host.

I'm somewhat at a loss concerning mysql_create_db. This is weird indeed. You can try: print_r(get_defined_functions()); and see if it's listed in the 'internal' part. Maybe you got some fluky php install that doesn't have the mysql functions. Unlikely, though, on a host that knows what he/she's doing, and advertises mysql as a feature.

Also see the note on the page of the manual for this function that it's deprecated and that you can use mysql_query.