Sign in to follow this  

[web] PHP/MySQL creating the setup pages

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm making a forum that's transferrable to a new domain. The only problem is that I've never made a script to create a database before, I've jsut had PHPMyAdmin create the database and set the user account on it for me, then I'd create the tables and processes from PHP/MySQL code. So I guess my question would be how to create a database thorugh code adn then create a user account and set a password up. Thanks in advance.

Share this post


Link to post
Share on other sites
phpBB 2.2 has a excellent setup script (I think the best "setup program" in PHP). You can get a full of ideas with it.

Download its latest CVS: Clicky

And so execute it. It's going to run the setup for first.
It's located on folder: /install

[Edited by - Maquiavel on September 14, 2004 10:43:05 PM]

Share this post


Link to post
Share on other sites
well since I don't want to copy anyone's work, and since I already have phpMyAdmin, how do I export the database commands? Or do you mean the box it displays after you insert a database command saying you've successfully added a table then the SQL CODE: $sql = "CREATE TABLE...etc.";

Share this post


Link to post
Share on other sites
never mind that question, it doesn't make any sense. What I need to know is why I can make a successful connection, but then it tells me this:

success in database connection. Access denied for user: 'demon@localhost' to database 'demon_test'


That doesn't make any sense. That's an error that normally shows up when you don't have the password correct, but I havn't set a password. I cant' till the database is created.
Here's my test code:

<?php

// set your infomation.
$dbhost='localhost';
$dbusername='demon';
$dbuserpass='mypassword';
$dbname='test';

// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";

// create the database.
$dbname=$dbusername."_".$dbname;
if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
echo "success in database creation.";

?>
<html>
<head>
<title>Demon Realms Studios&reg; Setup 2004</title>
</head>


<body bgcolor="#FFFFFF">
If you're seeing this message, then everything went well.
</body>


</html>

Share this post


Link to post
Share on other sites
Quote:
Original post by sathenzar
well since I don't want to copy anyone's work, and since I already have phpMyAdmin, how do I export the database commands? Or do you mean the box it displays after you insert a database command saying you've successfully added a table then the SQL CODE: $sql = "CREATE TABLE...etc.";


I didn't mean you to copy phpBB. I said to you see it and I'll learn what you want. I have had the same wish as you: create a PHP Setup Page. And with this of PHPBB I created a full-of-features one.

OpenSource is here for this: to learn with others' code, with experienced coders, otherwise it wouldn't exist open source.

In your code what is happenning is that the user 'demon' doesn't have permission to create databases. Starts your PHP script with the MASTER user, GRANT permissions to user 'demon' and so you will can create databases with no problems.

[Edited by - Maquiavel on September 14, 2004 10:49:23 PM]

Share this post


Link to post
Share on other sites
ok, I see what you ment now. Well the link you provided tells me it doesn't exsist, and as for the username not having permissions, I changed the username to demon_SIAD, which has full permissions and I have used it many times in webpages to edit/retrive information from my databases many times. But it's still giving me this error:
success in database connection.Access denied for user: 'demon_SIAD@localhost' to database 'demon_SIAD_test'
Any idea's? Maybe you could post a different link that provides me with the open source code? Thanks in advance.

Share this post


Link to post
Share on other sites
$sql = "create database namehere;";
Then make your tables with create table and then put the data in them with INSERT INTO. Check mysql.com for the docs on using them.
I pwn at php and sql. Writing a portal system at the moment and almost done with sessions and user access. [http://216.68.134.98/portal/ test site ]


[edit added link]

Share this post


Link to post
Share on other sites
Ok, I'm lost, could someone jus tpost the code they've used to create databases? This is kindof getting on my nerves. My whole programmign has been halted by this pointless problem, which shouldn't be happining in the first place. So could someone jsut post the code off of a page or somthing they;ve done that wiull create a database? Thanks.

Share this post


Link to post
Share on other sites
Just make your database in phpmyadmin and look at the sql code it shows when it says it was succesfull. Or once again look on mysql.com. Don't feel like coding for you, brain dead, too much math(on something else).

Share this post


Link to post
Share on other sites
ok I understand that no one would want to program it for me (to much time). So I was wondering, even in phpMyAdmin now it's saying error #1044 - Access denied for user: 'demon_SIAD@localhost' to database 'demon_test'. What get's me is before hand it says success in database connection.
if it successfully connected...then why is it saying Access Denied? This isn't makign any sense. I'm logged in why isn't it working?

Share this post


Link to post
Share on other sites
Ok, I"m about to go insane. I know this sounds really unprofessional but I"m starting to think MySQL is just a big p.o.s. that just sits there going, yep there he is agian, let's tick him off by denying him of the most simplest thing ever. I've been on this for days, I tell it to create adatabase and I expect it to do it. I'm tired of it saying "Well haha I'm so stupid I'm going to say a big **** you and have a nice day!" Like I said, it's not suppoesed to be hard logic. I'm just getting so mad that everyone else can do it but me, I know that sounds stupid but I'm at the end of my rope as of now. I can't do anything else for my site until I get this worked out.

Share this post


Link to post
Share on other sites
Whatever user you're logged in as does not have permission to create new databases, probably. mysql is not being a piece of shit, it's keeping your website from being hacked.

or, does that database already exist?

run the 'mysql' client, connect to the db, and do a 'show databases;'

Share this post


Link to post
Share on other sites
Arg! I will code you a database creation script as long as you jump3.rating++ me [wink]

[edit]
Do this for me first in phpmyadmin and replace the username and password from above with bob and try that. I made a super user.

GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , FILE , INDEX , ALTER , CREATE TEMPORARY TABLES ON * . * TO "bob"@ "%"IDENTIFIED BY "bob"WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 ;


That should work when queried off the admin account in mysql.

Share this post


Link to post
Share on other sites
I didn't have time to post this before.
Use the function 'mysql_create_db' in PHP to create databases.

Here is an example code, that works perfectly here:

<?php
$database = "baz";
$id = mysql_connect("localhost", "root", "") or die(mysql_error());


// Tries to select the database. If it can't select, tries
// to create the database...
if(!@mysql_select_db($database))
{
if(!mysql_create_db($database))
{
printf("I couldn't create database %s!", $database);
die;
}
// Database created... select it.
@mysql_select_db($database);
}

// code... code.. code..
?>





And if you want PHPBB, here is the latest version links: http://area51.phpbb.com/cvs/
Download a "phpBB 2.1.x Snapshots".

[Edited by - Maquiavel on September 14, 2004 10:38:52 PM]

Share this post


Link to post
Share on other sites
Thank you so much, there is only one problem left, nbow it gives me this error (whihc I'm saure is jsut a sp error):
Fatal error: Call to undefined function: mysql_create_db() in /home/demon/public_html/forums/setup/index.php on line 10
My page code:

<?php
$database = "baz";
$id = mysql_connect("localhost", "root", "") or die(mysql_error());


// Tries to select the database. If it can't select, tries
// to create the database...
if(!@mysql_select_db($database))
{
if(!mysql_create_db($database))
{
printf("I couldn't create database %s!", $database);
die;
}
// Database created... select it.
@mysql_select_db($database);
}

// code... code.. code..
?>
<html>
<head>
<title>Demon Realms Studios&reg; Setup 2004</title>
</head>


<body bgcolor="#FFFFFF">
If you're seeing this message, then everything went well.
</body>


</html>

Thanks for all of yor help so far, what is causing this erro though? if I could get past this one erro I'm set! -_-

Share this post


Link to post
Share on other sites
Well, I've run exactly this code here and it works well.
Do you really have MySQL extension loaded? This is the unique reason to PHP saying that the function create_db doesn't exist.

BUT, you can try mysql_createdb("blah"); too.

That a look here: http://www.php.net/manual/en/function.mysql-create-db.php

It must work, since it was in PHP since PHP3!

All the best.

Share this post


Link to post
Share on other sites
even though it says I created it successfully it doens't show up under phpMyAdmin, is this because the user it root, and the only user account I have created is demon_SIAD? OR anyone have any other idea's? Thanks.

Share this post


Link to post
Share on other sites
Hey, what's your PHP version?
Want a tip? Change it to the newer PHP5.

All this errors are very strange.. I haven't seen this before.

Quote:
Original post by sathenzar
even though it says I created it successfully it doens't show up under phpMyAdmin, is this because the user it root, and the only user account I have created is demon_SIAD? OR anyone have any other idea's? Thanks.


Oh.. open the config.inc.php of phpMyAdmin and change the settings to show all databases and change the user name too.

This is the problem.
Change these lines:

$cfg['Servers'][$i]['auth_type'] = 'config'; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = 'root'; // MySQL user
$cfg['Servers'][$i]['password'] = ""; // MySQL password (only needed
// with 'config' auth_type)
$cfg['Servers'][$i]['only_db'] = ""; // Let this blank, like this, to show all databases from the chosen user

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this