PDA

View Full Version : I can not access my database using a script on my website


johnny_o_neill
12-24-04, 10:25 PM
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

cleako
12-24-04, 10:45 PM
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;

cleako
12-24-04, 10:46 PM
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)

johnny_o_neill
12-24-04, 11:00 PM
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.

snowmaker
12-24-04, 11:09 PM
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.

cleako
12-24-04, 11:28 PM
yeah.. I was thinking about that as an issue.. but I didnt know about the numbering.. or ip adress to place there for powweb

cleako
12-24-04, 11:29 PM
- i'll have to figure that out when I need to activate my database php file..

snowmaker
12-24-04, 11:36 PM
When a db is activated in OPS, you'll be told what address the db has.

cleako
12-25-04, 12:03 AM
got it setup now.

johnny_o_neill
12-25-04, 10:53 AM
Yes, that's was it!! Thanks a bunch snowmaker.

Johnny O

snowmaker
12-25-04, 03:34 PM
You bet. Glad you got it.