Jump to content


Photo

Create Database


  • Please log in to reply
8 replies to this topic

#1 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 26 May 2006 - 01:27 PM

<?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`");
    }
?>

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\" /]

#2 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 26 May 2006 - 07:44 PM

Ok, i made a very simple test...

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

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...

#3 DoggerWatson

DoggerWatson
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 26 May 2006 - 11:14 PM

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

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

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.

#4 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 27 May 2006 - 10:56 AM

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.

#5 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 May 2006 - 01:54 PM

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

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

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.
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#6 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 27 May 2006 - 04:04 PM

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.
Im loving it ........

#7 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 27 May 2006 - 04:14 PM

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...

#8 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 27 May 2006 - 04:21 PM

[!--quoteo(post=377602:date=May 27 2006, 05:14 PM:name=Randy)--][div class=\'quotetop\']QUOTE(Randy @ May 27 2006, 05:14 PM) View Post[/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.


Im loving it ........

#9 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 27 May 2006 - 06:24 PM

[!--quoteo(post=377605:date=May 27 2006, 05:21 PM:name=avo)--][div class=\'quotetop\']QUOTE(avo @ May 27 2006, 05:21 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users