PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > MySQL
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools Search this Thread
Old 12-24-04, 10:25 PM   #1
johnny_o_neill
Registered
 
Join Date: Dec 2004
Location: Canada
Posts: 12
Reputation: 5
I can not access my database using a script on my website

If just starting using PHP and MySQL and I am starting to understand how it works, I just have one problem. When I tried to run a script to access the stuff in the database, It will not do it. I can go into phpMyAdmin and do all sorts of stuff with the database, but I can not access it when i try some php on my site. The following is an example of what i am using:

include("dbinfo.php");

mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

dbinfo.php is where I am storing the username and password info. Each time i run the script. i get the die result "Unable to select database"

I am thinkning it is something simple, but I am stumped, any suggestions

Johnny O
johnny_o_neill is offline  
Old 12-24-04, 10:45 PM   #2
cleako
 
Posts: n/a
okay.. i think its that your mysql connect with the whole localhost, username and password isnt filled in right.. i'm prob wrong, but heres what I've used in the past (not with powweb yet)

(since my sites still being set up) - (the parts such as database, password and username are what you fill in)

* Connect to the mysql database.
*/
$conn = mysql_connect("localhost", "database_username
", password ) or die(mysql_error());
mysql_select_db('database_username', $conn) or die(mysql_error());
GLOBAL $conn;

-----

the original php code that was written for me was:

* Connect to the mysql database.
*/
$conn = mysql_connect("localhost", "da_cleako", "cleako") or die(mysql_error());
mysql_select_db('da_cleako', $conn) or die(mysql_error());
GLOBAL $conn;
 
Old 12-24-04, 10:46 PM   #3
cleako
 
Posts: n/a
now that code never worked for me when i tried with fortune city.. but their mysql never worked.. and fortune city is the number 1 worse ever host.. so as soon as my domain is transfered from them to here, i'll know if the code works here.. (along with setting up a database here)
 
Old 12-24-04, 11:00 PM   #4
johnny_o_neill
Registered
 
Join Date: Dec 2004
Location: Canada
Posts: 12
Reputation: 5
Thanks, but that didn't help. I've tried everything i could find, different variations on how to write the code, but nothing is working. I'm just trying to make a page that will let me access the info in the database, but I haven't figured out how yet.
johnny_o_neill is offline  
Old 12-24-04, 11:09 PM   #5
snowmaker
 
 
snowmaker's Avatar
 
Join Date: Nov 2002
Location: Solomons Island
Posts: 2,217
Reputation: 212
Quote:
Originally Posted by johnny_o_neill
include("dbinfo.php");

mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

dbinfo.php is where I am storing the username and password info. Each time i run the script. i get the die result "Unable to select database"

I am thinkning it is something simple, but I am stumped, any suggestions
Don't use 'localhost', instead, use the 'mysqlxx.powweb.com' that you use to connect to your db with phpmyadmin.
__________________
-bruce /* somdcomputerguy */
'If you change the way you look at things, the things you look at change.'
snowmaker is offline  
Old 12-24-04, 11:28 PM   #6
cleako
 
Posts: n/a
yeah.. I was thinking about that as an issue.. but I didnt know about the numbering.. or ip adress to place there for powweb
 
Old 12-24-04, 11:29 PM   #7
cleako
 
Posts: n/a
- i'll have to figure that out when I need to activate my database php file..
 
Old 12-24-04, 11:36 PM   #8
snowmaker
 
 
snowmaker's Avatar
 
Join Date: Nov 2002
Location: Solomons Island
Posts: 2,217
Reputation: 212
When a db is activated in OPS, you'll be told what address the db has.
__________________
-bruce /* somdcomputerguy */
'If you change the way you look at things, the things you look at change.'
snowmaker is offline  
Old 12-25-04, 12:03 AM   #9
cleako
 
Posts: n/a
got it setup now.
 
Old 12-25-04, 10:53 AM   #10
johnny_o_neill
Registered
 
Join Date: Dec 2004
Location: Canada
Posts: 12
Reputation: 5
Yes, that's was it!! Thanks a bunch snowmaker.

Johnny O
johnny_o_neill is offline  
Old 12-25-04, 03:34 PM   #11
snowmaker
 
 
snowmaker's Avatar
 
Join Date: Nov 2002
Location: Solomons Island
Posts: 2,217
Reputation: 212
You bet. Glad you got it.
__________________
-bruce /* somdcomputerguy */
'If you change the way you look at things, the things you look at change.'
snowmaker is offline  
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 10:21 AM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright © 2000-2007 Jelsoft Enterprises Limited.