TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-19-2008, 12:30 PM   #1 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default Beginners Problem

Hey,
I'm having a problem with MySQL. I am using my hosting at hostgator .com and it was all going well until I tried to create a database.
Here is my php (username and password excluded:
PHP Code:
<?php
mysql_connect
("localhost""""") or die(mysql_error());
echo 
"Connected to MySQL<br />";
mysql_query("CREATE DATABASE test") or die(mysql_error());
echo 
"Connected to Database<br />";
?>
It connects to the server but doesn't create the database, saying access is denied. I tried using MySQL Database, the MySQL software that comes with the hosting and I managed to create the database and connect to it there but it won't let me do it through PHP!

I would like a PHP solution because I'm interested in writing CMS's. Thanks.
Normo is offline  
Reply With Quote
Old 11-19-2008, 01:24 PM   #2 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

I think you are not allowed to create a database. You might want to create a table. Shared hosting providers usually don't give you a whole Mysql-server, only a single database. So there should allready be a database for you, in which you can create multiple tables with the 'CREATE TABLE' statement.
__________________
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
Old 11-19-2008, 02:57 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Free hosts usually only allows 1 database. Perhaps you already have a database.

If not, then probably it's like awuehr said that you don't have permission to create a database like that. Only via the PHPMyAdmin
__________________
Tanax is offline  
Reply With Quote
Old 11-19-2008, 07:57 PM   #4 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default

I have an account that allows me to make unlimited databases, therefore I assumed I would be able to create them outside of the admin system. :/

Can I create tables outside of a database then? :S
Normo is offline  
Reply With Quote
Old 11-20-2008, 03:02 AM   #5 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Quote:
Originally Posted by Normo View Post
I have an account that allows me to make unlimited databases, therefore I assumed I would be able to create them outside of the admin system. :/

Can I create tables outside of a database then? :S
Hmm, as far as i experience, most of the freehost usually do is that give you only one database for you to use in any way you want it. Then just create multiple tables under that single database.

So if you really have an account that can make unlimited databases, then it wont give you any problems usually. Just try to replace some of the value in your codes.

Your code
Code:
<?php 
mysql_connect("localhost", "", "") or die(mysql_error()); 
echo "Connected to MySQL<br />"; 
mysql_query("CREATE DATABASE test") or die(mysql_error()); 
echo "Connected to Database<br />"; 
?>  [IMG]file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot.jpg[/IMG][IMG]file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot-1.jpg[/IMG][IMG]file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot-2.jpg[/IMG][IMG]file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot-3.jpg[/IMG]
Change it to
PHP Code:
<?php
$host 
'the domain of the hosting here';
$u_host 'something'#username of your account that can create unlimited database
$p_host 'something'#password of your account that can create unlimited database

$link mysql_connect($host$u_host$p_host)or die("Error: Could not connect to the database server");
if (
$link){
  
$q_create "create database test";
  
mysql_query($q_create$link)or die("Error: Could not create database!");
}else{
  return 
false;
}
?>
Take note that "test" is already existing in a mysql server unless it is remove by admin(if im not mistaken about it). So try to put other names as a sample.

Quote:
Originally Posted by Normo View Post
Can I create tables outside of a database then? :S
You cannot create a tables outside a database. It works this way, you can't sit if you dont have a chair. Easy right?


Regards,
t3st
zxt3st is offline  
Reply With Quote
Old 11-20-2008, 09:14 AM   #6 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default

It's not free hosting, it is paid for.

Still no luck however. I've contacted hostgator support.
Normo is offline  
Reply With Quote
Old 11-21-2008, 05:27 AM   #7 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

hmm, btw what does the hosting using? control panel? I think the hosting should be giving you instructions about how their system works though.

But its a very good move to contact for their support.
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 11-22-2008, 04:19 PM   #8 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default

cPanel yeah. It turned out that you can't create databases through PHP because of the risk of screwing up cPanel or something. You just need to set up the databases through the MySQL Databases software.
Normo is offline  
Reply With Quote
Old 11-22-2008, 07:28 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Most shared hosts don't let you do those types of things though scripting languages because of permission issues. Just let the cPanel database manager do it.
__________________

Village Idiot is offline  
Reply With Quote
Old 11-26-2008, 05:20 AM   #10 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Quote:
Originally Posted by Normo View Post
cPanel yeah. It turned out that you can't create databases through PHP because of the risk of screwing up cPanel or something. You just need to set up the databases through the MySQL Databases software.
have you figure out your problem already ? Have you created your database already?
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 11-26-2008, 11:32 AM   #11 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default

Yeah I can only do it through the MySQL Databases tool, not through PHP. I just created it in the tool and then you can access it with PHP fine. :)
Normo is offline  
Reply With Quote
Old 11-27-2008, 03:34 AM   #12 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Okies, solve solve solve !
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 11-28-2008, 06:03 AM   #13 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

I any server that I have found you can create more than one database. Does anyone remember the Y2k bug? Well I don't lol i was like 8 or 9 when all this happen but a buddy of mine told me about. No body anticipated that the systems they wrote will go into next century, so they never used full year like 1998. They only used 98, so computer added 19 automatically. The here comes the year 2000. Input 00 and and the computer added 19 so it became it became 1900. That was the whole problem and huge issue back in year 2000. People spent hundreds of billions of dollars to upgrade their systems. Anyhow that is a bad design and their is still a lot of problems and they will face that another 100 years which we do not give a damn lol but. Because of all that their are still massive bugs that still remain.
KingOfTheSouth is offline  
Reply With Quote
Old 11-28-2008, 08:22 AM   #14 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Quote:
Originally Posted by KingOfTheSouth View Post
I any server that I have found you can create more than one database. Does anyone remember the Y2k bug? Well I don't lol i was like 8 or 9 when all this happen but a buddy of mine told me about. No body anticipated that the systems they wrote will go into next century, so they never used full year like 1998. They only used 98, so computer added 19 automatically. The here comes the year 2000. Input 00 and and the computer added 19 so it became it became 1900. That was the whole problem and huge issue back in year 2000. People spent hundreds of billions of dollars to upgrade their systems. Anyhow that is a bad design and their is still a lot of problems and they will face that another 100 years which we do not give a damn lol but. Because of all that their are still massive bugs that still remain.
Im sorry but im confuse/i didn't get your point. Will you care to elaborate more on what is the connection on having multiple databases on any server(as if not a freehost) with the y2k bug?
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 11-29-2008, 02:49 AM   #15 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

I do not know either i thought it was about the database design
KingOfTheSouth is offline  
Reply With Quote
Old 11-29-2008, 03:08 AM   #16 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Its all about his problem which is "Why can't he create a database through his own php script"

Though no worries :)
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:43 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design