Jump to content

Archived

This topic is now archived and is closed to further replies.

Randy

Create Database

Recommended Posts

[code]<?php
    // ----------
    $host = "localhost";
    $user = "electri_ryan";
    $pass = "*********";
    // ----------
    mysql_connect($host, $user, $pass) or die("Error Connecting: ".mysql_error());
    $dbs = mysql_list_dbs();
    if(mysql_num_rows($dbs) > 0){
        while(list($db) = mysql_fetch_row($dbs)){
            if($db == "forums"){
                $exists = true;
            }
        }
    }
    if(!$exists){
        echo("Database does not exist!");
        // Create database...
        mysql_query("CREATE DATABASE `forums`");
    }
?>[/code]

Ok, when i run this code, no errors, and it echoes out "Database does not exist!", but when i look in cPanel, there is not a database calles forums...

Anybody know what is wrong? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

Share this post


Link to post
Share on other sites
Ok, i made a very simple test...

[code]<?php
    mysql_connect("localhost","electri_ryan","*********");
    mysql_query("CREATE DATABASE `forums`") or die(mysql_error());
?>[/code]

When i run this i get the error:

Access denied for user: 'electri_ryan@localhost' to database 'forums'

Do i have to set privileges or something? 'electri_ryan' has all privileges...

Share this post


Link to post
Share on other sites
[!--quoteo(post=377386:date=May 26 2006, 02:44 PM:name=Randy)--][div class=\'quotetop\']QUOTE(Randy @ May 26 2006, 02:44 PM) [snapback]377386[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ok, i made a very simple test...

[code]<?php
    mysql_connect("localhost","electri_ryan","*********");
    mysql_query("CREATE DATABASE `forums`") or die(mysql_error());
?>[/code]

When i run this i get the error:

Access denied for user: 'electri_ryan@localhost' to database 'forums'

Do i have to set privileges or something? 'electri_ryan' has all privileges...
[/quote]
from 1 Noob to another Noob, if all you want to do is create a db; why not use the PHPMyAdmin from your CPanel. No point doing things the hard way.

Share this post


Link to post
Share on other sites
NO, i do not want to create a database using cPanel, i was making a forum that is dynamic and can be put on a website easily.

Share this post


Link to post
Share on other sites
[!--quoteo(post=377386:date=May 26 2006, 02:44 PM:name=Randy)--][div class=\'quotetop\']QUOTE(Randy @ May 26 2006, 02:44 PM) [snapback]377386[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ok, i made a very simple test...

[code]<?php
    mysql_connect("localhost","electri_ryan","*********");
    mysql_query("CREATE DATABASE `forums`") or die(mysql_error());
?>[/code]

When i run this i get the error:

Access denied for user: 'electri_ryan@localhost' to database 'forums'

Do i have to set privileges or something? 'electri_ryan' has all privileges...
[/quote]

I have noticed that some ISPs do not allow you to create databases this way. I am only taking a shot in the dark, but can you create a new database from phpMyAdmin? My current ISP does not allow me to do this (I'm sure it has something to do with a server configuration/setup that is beyond me). I can only create new databases within cPanel. Hopefully that explains your mystery, if not, I would love to hear the outcome.

Share this post


Link to post
Share on other sites
Hi

Is apache setup correct on you pc ?
Have you got a full white dial ?
can you connect and loginto phpmyadmin manualy?

let me know your results.

first these will need to be working as i noticed you are connecting to a localhost if you are connecting to a external server then this will need to be address with the correct connection data not localhost.


hope this helps.

Share this post


Link to post
Share on other sites
I am running this script on my server, not on my computer

i use localhost all the time for select, update, insert and such and it always works...

Share this post


Link to post
Share on other sites
[!--quoteo(post=377602:date=May 27 2006, 05:14 PM:name=Randy)--][div class=\'quotetop\']QUOTE(Randy @ May 27 2006, 05:14 PM) [snapback]377602[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I am running this script on my server, not on my computer

i use localhost all the time for select, update, insert and such and it always works...
[/quote]

HI

If this is your server and on the same internet connection you would use something like 192.168.1.101 or localhost (no firewall or routed )(in your house)
for example

if your server is running from somewhere else in the world (one you are paying for)you would use there connection address.wwwservername.co.uk

which one is it ?

cheers.

Share this post


Link to post
Share on other sites
[!--quoteo(post=377605:date=May 27 2006, 05:21 PM:name=avo)--][div class=\'quotetop\']QUOTE(avo @ May 27 2006, 05:21 PM) [snapback]377605[/snapback][/div][div class=\'quotemain\'][!--quotec--]
HI

If this is your server and on the same internet connection you would use something like 192.168.1.101 or localhost (no firewall or routed )(in your house)
for example

if your server is running from somewhere else in the world (one you are paying for)you would use there connection address.wwwservername.co.uk

which one is it ?

cheers.
[/quote]

the www.electric-monkey.com/ type

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.