开发者

Cannot connect to my hosting service's MySql database. NB

I am EXTREMELY new to the html/php scene but I have been working at this for hours. I am stumped.

I am trying to connect to a sql database that will store username and password information. I use fortune city for hosting and I have already used their phpAdmin to setup up all of the necessary stuff (db, tables, etc..).

I am using Eclipse with Zend on the side. I am also running Sql Server and Apache 2.2.

I believe my issue is the following:

I have a db located at a certain ip address (remote fortunecity server) and I am testing my project on the local server. Fortune city offers two different host names, one for internal connections and one for external connections. I get different results from each one:

If I connect to the internal site it doesn't make any connection, I know this because of my die statement. If I connect to the external host it connects, but doesn't allow me to connect to the database. (see cases below code)

Currently my process is as follows. (PLEASSSSE TELL ME A BETTER WAY IF I'M DOING THINGS THE INEFFICIENTLY, I feel dirty every time I do it!!)

  1. Create or edit my index.php, login.php, etc... in eclipse.
  2. Copy the files that I edit into my Apache root.
  3. Go back to eclipse and run the project in a browser "firefox."
  4. repeat n to the n times.

Keep in mind my sql database is located on the net

Can this be done? Testing locally while accessing a db on the net?

Here is the code:

<?php

if (!isset($_POST['username']) || !isset($_POST['password'])) {
header( "Location: http://localhost/index.php" );
}

elseif (empty($_POST['username']) || empty($_POST['password'])) {
header( "Location: http://localhost/index.php" );
}
else{

$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);


$dbHost = "mysql3341.dotsterhost.com";
$dbUser = "*********";
开发者_StackOverflow中文版$dbPass = "******";
$dbDatabase = "**********";


$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

$result=mysql_query("select * from userInfo where username='$user' AND password='$pass'", $db);


$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){



session_start();
session_register('username');


echo 'Success!';


header( "Location: checkLogin.php" );

}

}
else {



echo 'Incorrect login name or password. Please try again.';
}
}
?> 

Again, I have never made it past

Case :1 $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");

Case :2 mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

Thanks for reading my novel!


Can this be done? Testing locally while accessing a db on the net?

Yes you can, but be aware if you are storing anything sensitive in your database you probably wouldn't want to be sending that data unencrypted over the net. (Unless you are connecting over a VPN or another type of secure network connection.)

Usually you'd want to setup a development environment on your local box or you can edit your files locally in something like Aptana (http://www.aptana.com/) and have it automatically deploy your files to the server every time you save.

Also, as suggested in the comments, using a framework to develop on usually give you a powerful database library without the need to reinvent it on your own. (That is unless you feel like wrapping your own!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜