LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-13-2003, 09:34 AM   #1
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Rep: Reputation: 30
Question mysql database creation


I have mysql, apache, php, and webmin installed on my machine and would like to create a new mysql database with webmin. I go to create a new database and from there i am lost... Can someone point me in the right direction to get this new database created. I want to be able to have a site that will enter information and pull information back from this database with php.
 
Old 05-13-2003, 09:44 AM   #2
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
That is a pretty broad question. Let me see if I can get you going a bit.

First off you have to create the database, which I think you did already then you have to create a table in the database with fields like:

id
data_name
data

Then you have to set up a user that is allowed to connect to that database, this is all easly done from webmin.

You could then use php to add and display the data from the database. This is the hard part, you might want to check out a book on php or find a online manual for this.

http://hotwired.lycos.com/webmonkey/...tutorial4.html

That link may help you with the php stuff, there is alot out there to help you. For specific php help you might want to try:

http://www.phpbuilder.com/board/

They have alot of info there you can search through.


Past that if you have any more specific questions ask away.
 
Old 05-13-2003, 09:58 AM   #3
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
You're right, that is a broad question... I will try to narrow it down. From webmin I click create database, it brings up a 'New database options' dialog. This is where it starts getting a little fuzzy, 'Database Name (that i can understand), 'Initial Table = none', 'Initial Table Structure' - not sure what these options are. I am new to databases and unfamiliar with their terminology. I still don't think I've actually asked a question but I knew this was the best place to start.
 
Old 05-13-2003, 11:04 AM   #4
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
Ok we can work with that, I will start here and see where it goes.

1st. Go into webmin and click on create database put in the name you want for the database and click none on the intial table and don't fill out the rest click create.

Then you have to decide what data you are putting into the database. for a simple one that holds employee addresses you would click on the database you just created and click create new table, you will have to put in how many fields you want in it, for our address's table there would be 4

id - type will be "int" width will be 4
name - type will be "varchar" widht will be 60
address - type will be "varchar" width will be 100
phone - type will be "varchar" width will be 15

you will put in the fields shown above into the new table and then click create table, this is now a database that is ready to accept data.

Now you should never access a normal database as the root database user so you need to create a mysql user in webmin, this is done the same place that you created the database. Click on on user permissions then create new user, give them a username and a password and set the hosts to localhost don't give them any permissions.

Save that user and then go to database permissions, (same places as add new database and users) and click create new database permissions. Select your new database. then type in the username you just created and set the hosts to localhost. Give them full permissions, (select all the options from the list) and then save that.

You will now have a working database with a user set up to access it. whew.
 
Old 05-13-2003, 11:27 AM   #5
KennyK
Member
 
Registered: Apr 2003
Location: California, USA
Distribution: Redhat 8.0, 9.0 Suse 9.0 Pro
Posts: 129

Rep: Reputation: 15
After reading this post and what you have running it occured to me that you might be trying to setup phpnuke or postnuke. If this is the case, then follow the instructions that cli_man posted, except that these programs have built in scripts to create the tables for you.

If not, and you are writing your own php script that you want to use mysql then ignore what I am saying and do everything that he posted.

Regards
 
Old 05-13-2003, 11:53 AM   #6
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
From his origanol questions I took that he wanted to set up the database and programming from scratch. But if he is trying to install a php program that needs mysql support he would not have to worry about creating the tables just the database and permissions like I said above.
 
Old 05-13-2003, 02:01 PM   #7
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
Cli_man you are correct I am trying to set this up from scratch. I followed your instructions on the database side and all worked well. Now I have some php code that I got from somewhere else with someone trying to do basically the same as me. However it does not work for me, any suggestions, below is the code, thanks in advance.


<?
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * From Customer_Information WHERE Title like '%Customer%'";

$result=mysql_query($query) or die (mysql_error());

while ($row=mysql_fetch_array($result))
{
echo $row['fieldname'];
}

?>
 
Old 05-13-2003, 02:26 PM   #8
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
Your mysql_query does not look right, I normally have 2 variables in it, here is what I use to get data out of the database.



<?

$db_name = "data_name";
$db_user = "me";
$db_pass = "me_pass";

$connection = mysql_connect("localhost", "$db_user", "$db_pass") or die("Couldn't Connect");
$db = mysql_select_db($db_name, $connection) or die("Couldn't Select Database");

$sql = "select * from Customer_Information";
$result = mysql_query($sql, $connection) or die("Couldn't Execute query.");
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];

$text .= "$id $name <br>";
}
echo $text;
?>

Last edited by cli_man; 05-13-2003 at 02:29 PM.
 
Old 05-13-2003, 03:15 PM   #9
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
Couldn't Connect is what I get in the browser. Below is exactly what I have:

<?

$db_name = "test";
$db_user = "testphp";
$db_pass = "test";

$connection = mysql_connect("localhost","$db_user","db_pass") or die("Couldn't Connect");
$db = mysql_select_db($db_name, $connection) or("Couldn't Select Database");

$sql = "SELECT * from Customer_Information";
$result = mysql_query($sql, $connection)or die ("Couln't execute query.");
while ($row = mysql_fetch_array(result)) {
$id = $row['id'];
$name = $row['name'];

$text = "$id $name <br>";
}
echo $text;
?>

The database is test, and the table is Customer_Information.
 
Old 05-13-2003, 03:28 PM   #10
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
You might be running into a register_globals problem. I didn't think of that, all of my programming has been done with register_globals set to on and the default now is off, you can check by making a php file that only has this in it:

<? phpinfo() ?>

Then go to that page and see if register_globals is set to on or off. Post back what you find.
 
Old 05-13-2003, 03:47 PM   #11
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
register_globals is Off
 
Old 05-13-2003, 04:00 PM   #12
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
Ok, I think that may be the problem with the script I gave you. You have to access variables differently when the register_globals is off, I haven't gotten into that yet because I haven't had the time. For now if you want you could turn it to on (sidenote This makes your scripts less secure)

To turn it to on find you php.ini file and find where it says register_globals and change it from off to on, save the file and restart apache. Then that script should work for you.

And just to say again what I did above, it is a good thing to have register_globals set to off, I just don't know how to program with it that way yet.
 
Old 05-14-2003, 09:11 AM   #13
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
I turned globals on and it still doesn't connect. It is still failing on line 7, couldn't connect. Maybe a database permissions problem?? I've deleted and started over with a new database but still doesn't work.
 
Old 05-14-2003, 09:18 AM   #14
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
A couple of things I didn't notice before, in the script you pasted above on line 7 you need a space after the , after localhost and db_user Also on line 8 you need to have or die not just or

Also on line 12 your result should be $result

I will keep looking.
 
Old 05-14-2003, 10:20 AM   #15
zuessh
Member
 
Registered: Jun 2002
Location: USA
Distribution: Suse 8.0
Posts: 247

Original Poster
Rep: Reputation: 30
I had a typo on line 7 also ($db_pass), I changed that and the other and now I am stuck on 'Couldn't execute query'

Gaining gound...
 
  


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
Writing an app that uses a mysql database without installing mysql server? QtCoder Programming 4 08-09-2004 02:43 PM
Mysql table creation problems!! linux_child001 Linux - Newbie 10 06-28-2004 01:10 PM
MYSQL help - mysql database missing eloviyandhi Linux - Software 1 03-20-2004 09:20 PM
Mysql database from cd JHuizingh Linux - Software 0 02-22-2003 02:08 PM
mysql database huno Linux - General 8 02-11-2003 08:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:44 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