LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2005, 07:22 PM   #1
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Rep: Reputation: 30
php mysql initial connect to create db


Hi I am building a "drag-n-drop" guestbook in php and mysql. The idea is for a user to upload a folder at the server root similar to the way phpbb works. The one thing I can't figure out is how do you connect mysql initially. I understand that administrators are going to use different methods but TYPICALLY would the user name and password they use to access the server work as permissions to connect to the database?
I am looking for a way to set up the database without the user having to do anything, if that is possible.
Thanks

Last edited by spoody_goon; 05-02-2005 at 07:26 PM.
 
Old 05-03-2005, 02:16 PM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
hrm, you would encapsulate sql commands in your PHP, one of which is create database. Fairly sketchy way to do things, but that's all you'd do.
 
Old 05-03-2005, 03:34 PM   #3
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
that is true, I guess I mis-worded the question, with most apache servers is user permissions enough to create a database and grant permissions to that database.
 
Old 05-03-2005, 05:29 PM   #4
mandeltuete
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Fedora 3
Posts: 75

Rep: Reputation: 15
AFAIK user permissions lay on mysql's side. So the user would have to create a mysql user and grant access to create databases, etc. There is no default user to create db's, because that would be quite insecure. Imagine if every script could create free db's. Which username and password do you mean exactly, which are the same? There's definitely no default one.

hth
phy

Last edited by mandeltuete; 05-03-2005 at 05:32 PM.
 
Old 05-03-2005, 06:03 PM   #5
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
but using php I could create a db user from the apache user permisions? I could do this with a grant statement?
I think I know the answer but I would like some "backup"
 
Old 05-04-2005, 05:25 AM   #6
mandeltuete
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Fedora 3
Posts: 75

Rep: Reputation: 15
Apache has no rights to create dbs in mysql, so your user has to give you a mysql user and its password during the installation. You could prompt him for the root user to be able to create new mysql users..
 
Old 05-04-2005, 11:02 AM   #7
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
apache does nothing, you're wrapping up your sql commands in php, which includes things like logging in to sql via php which happens to be used by apache.

The username and password you're using inside your php will already be there by you. The problem comes in, everyone could then create a database on your server, which could possibly open up your server for very bad things to happen if your code isn't secure....heck, even if it is, you could still create endless DBs to the point that I'm sure mysql will die.

For instance, here's a snippet of code I use to use on my site to grab specific stories for people to view:

Code:
$MYdatabase = "RogerDodger";
$MYhost = "localhost";
$MYuser = "have-you-any-wool";
$MYpassword = "bah-bah-blacksheep";
$MYtable = "nuke_stories";
$MYitem_topicid = 37;
$MYurlStartString = "<li><a href=\"http://www.technoslave.net/modules.php?op=modload&name=News&file=article&sid=";
$MYurlEndString = "&mode=thread&order=0&thold=0\">";
$MYcloseHref = "</a></li>";

// END OF CONFIG ... DO NOT CHANGE BELOW THIS LINE

$MYconnected = mysql_connect($MYhost, $MYuser, $MYpassword);

if ( !$MYconnected ) {
        die("<BR>" . mysql_errno().": ".mysql_error()."<BR>");
}

$MYdb = mysql_select_db($MYdatabase);
The above is php, in place of say mysql_select_db, you'd find the php that allows you to create a database.

Anyway, hope that helps, but either way, creating DBs from a web link is sketchy.
 
Old 05-05-2005, 05:45 PM   #8
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
Sorry for the delay in getting back to you, I had family type stuff to do.

Quote:
Originally posted by mandeltuete
Apache has no rights to create dbs in mysql, so your user has to give you a mysql user and its password during the installation. You could prompt him for the root user to be able to create new mysql users..
My expeiance with remote servers (I use mine just for testing) is with vdeck and cpanel both have utilities to add a user, create a database and then add the user to the database. The users I want to target with this program would not have access to root permissions, but I want to make it user friendly.

I think that I will have to instruct users how to create the databases and users and go from there, is that your take on it mandeltuete? Of course users with root permisions this would change.

Are there any file based databases for php like there is for ms access or perl db_file?

Thanks you both for your help
 
Old 05-06-2005, 03:56 PM   #9
mandeltuete
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Fedora 3
Posts: 75

Rep: Reputation: 15
Quote:

I think that I will have to instruct users how to create the databases and users and go from there, is that your take on it mandeltuete? Of course users with root permisions this would change.
Yes, somehow. You can write an installation script with php which handle all things like creating users and databases. The user had to give you a username and password of mysql. In your installation script you then connect with the supplied username and password to mysql, create a new user and a new database, all tables you need, etc.
That means your users can be newbies, they only need a username and a password.

Last edited by mandeltuete; 05-06-2005 at 03:57 PM.
 
Old 05-06-2005, 04:46 PM   #10
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
Thanks I believe that is the best way to go it's nice to have a second opinion. I have thought about a text file based database for later releases have you looked at http://www.c-worker.ch/txtdbapi/index_eng.php ?
 
Old 05-07-2005, 09:20 AM   #11
mandeltuete
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Fedora 3
Posts: 75

Rep: Reputation: 15
Never used it before, but it looks quite nice for smaller projects. I remember old days when I scripted guestbooks, had to save all messages in a text file and create my own little bugfull api :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP can't connect to MySQL westchester Linux - Software 13 07-02-2005 10:45 PM
PHP Can Not Connect To MYSQL ombill Fedora 4 09-06-2004 01:24 PM
Can't connect to MySQL server using PHP Lars79 Linux - Newbie 3 08-05-2004 03:13 PM
php can connect mysql, but can't do anything else? towlie Programming 2 04-26-2004 04:17 PM
Can't connect MySQL through PHP mac Programming 1 02-18-2002 09:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration