views:

281

answers:

5

Hi, I'm using GoDaddy's Shared Linux hosting and some PHP I wrote just won't work with my DB on the server.

EDIT:

I fixed the problem. I accidentally deleted the "database" connection variable from a config file. Wow. That was silly of me.

EDIT:

By not work, I mean that I can't read the DB. I've messed around enough to know that the DB is running and that when I modify the password variable I get 'Access Denied'. Furthermore, on localhost, the password is different and it works.

EDIT 2: I am now working with the sample script from GoDaddy. It now shows up a blank page. At least there are no errors... I changed the password to be alphanumeric. I am not using 'localhost'.

EDIT 3: With the correct password and server info I get the following error using mysql_error(). I am not using a leading http:// in the db url.

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Edit 4:

Here is my connection code.Please note that nl() and report() are predefined functions that echo newlines and diagnostic messages respectively. The connection variables are in an external file, included above. I've checked - the includes are working just fine.

//////////////////////////////
// Connect to the database  /////////////////////////////////////////
//////////////////////////////

//report -  Attemting to establish connection ...
report(4);

////
//Step 1) Set connection in variable
////

$conn = mysql_connect($server, $user, $pass);

////
// Step 2) Verify the connection
////

if(!$conn){
    //report - failed, see next line...
    report(5);
    //report - FATAL ERROR: Check database name, username and password.
    report(9);      
}else{
  //report - done!
  report(7);
}

//report - Selecting database ...
report(6);

////
// Step 3) Select the database
////

$db_select = mysql_select_db($database);

////
// Step 4) Verify successful selection
////

if(!$db_select){
    //report - failed, see next line...
    report(5);
    //report - FATAL ERROR: Could not select database.
    report(8);  
}else{
  //report - done!
  report(7);
}

//report -  Running query ...
report(10);

////
// Step 5) Create the original the query
////

$selector = " * ";
$target = "`properties`";
$condition = "1";

$sql = "SELECT " . $selector . " FROM " . $target . " WHERE " . $condition;

////
//  Step 6) Check for a $_GET[] parameter
////

if($_GET['listing'] && !is_null($_GET['listing'])){                 //if a listing number was supplied
    $listingNum = htmlentities($_GET['listing']);                   //safety first - clean it from code injections      
    $pattern = '/\b[0-9]{1,6}\b/';                                  //define a range of valid, sercheable listings
    if(preg_match($pattern,$listingNum) == 1){                      //if the listing id is a valid one
        $sql .= " AND `listing_id` =" .$listingNum . "";            //search for it in the database
    }elseif($exp == 0){                                             //if the listing number is out of range   
        if($listingNum != "all"){                                   //check if the "all" keyword was ommitted - if it was not supplied.
            //report - failure ... see below
            report(5);
            //report - Invalid listing ID
            report(12);
            //
            // Invalid Listing ID...
            //
        }       
    }
}else if(!$_GET['listing']){
    //report - failure ... see below
    report(5);
    //report - Invalid listing ID
    report(12);
    //
    //No listing ID
    //
}


if(!$sql){
    //report - failed, see next line...
    report(5);
    //report - FATAL ERROR: Could not run query.
    report(11);
    //
    // For some reason the query doesn't exist here. I really do wonder why.
    //
}else{
  //report - done!
  report(7);
  nl();
}

$result = mysql_query($sql);    //perform the actual query

if(!$result){
    echo("There's been some sort of error with the search lookup. Here are the details: \n" . mysql_error());
}

mysql_close($conn);         //close the connection to the SQL server
A: 

Have you ever accessed the database before? Do you have phpMyAdmin installed? and the hash shouldn't be the problem. If it let you set it as a password then you can log in for sure. Would you post the code you're using so we can check if out?

B Squared
I've accessed other DBs on GoDaddy before, not this one. I think the fact that ther'es a # in the middle messes with things because it's PHP's comment character. (Aside from /**/ and //) Perhaps GoDaddy/PHPMyAdmin have some way of parsing it.
Moshe
The hash is comment as long as it's outside a string. It has nothing to do with it.
metrobalderas
A: 

I've used GoDaddy once or twice (terrible service btw), and as long as I can remember, the mysql host, which is 98% localhost, should be set to another host, but I'm not sure. Maybe you should start checking there.

metrobalderas
+1  A: 

Did you use "localhost" in mysql connection?

Most of the hosting service host mysql on differernt machine and normally localhost does not work, need to put exact url provided by your server.

And the char "#" in the password should not be problem, but your password should be inside quote like '123#123', I am not sure 123#123 will work or not.

S.Mark
+1 for the bit about the pwd.
Moshe
+1  A: 

For GoDaddy, you must not use localhost as the database server. There is sample PHP code under Databases -> MySQL in the hosting manager that can help.

chpwn
I am **not** using localhost as the server.
Moshe
A: 

Note to self:

Next time something like this happens, confirm which database you are selecting in MySQL

Moshe