TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   Beginners Problem (http://www.talkphp.com/mysql-databases/3630-beginners-problem.html)

Normo 11-19-2008 12:30 PM

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.

awuehr 11-19-2008 01:24 PM

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.

Tanax 11-19-2008 02:57 PM

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

Normo 11-19-2008 07:57 PM

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

zxt3st 11-20-2008 03:02 AM

Quote:

Originally Posted by Normo (Post 19749)
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 (Post 19749)
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? :-D


Regards,
t3st

Normo 11-20-2008 09:14 AM

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

Still no luck however. I've contacted hostgator support.

zxt3st 11-21-2008 05:27 AM

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.

Normo 11-22-2008 04:19 PM

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.

Village Idiot 11-22-2008 07:28 PM

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.

zxt3st 11-26-2008 05:20 AM

Quote:

Originally Posted by Normo (Post 19822)
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?

Normo 11-26-2008 11:32 AM

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

zxt3st 11-27-2008 03:34 AM

Okies, solve solve solve !

KingOfTheSouth 11-28-2008 06:03 AM

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.

zxt3st 11-28-2008 08:22 AM

Quote:

Originally Posted by KingOfTheSouth (Post 19967)
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? :-!

KingOfTheSouth 11-29-2008 02:49 AM

I do not know either i thought it was about the database design

zxt3st 11-29-2008 03:08 AM

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

Though no worries :)


All times are GMT. The time now is 08:47 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0