网站迁移到雪豹服务器后,“没有数据库选择”

I'm migrating a website from a windows server to a snow leopard server (OSX 10.6.8 to be exact) and I'm running into several compatibility issues with my mysql queries. Every query returns a "No database selected" error and I can't make heads or tales of it. I've done some research on it and wasn't able to find the answer I was looking for. Here are some indicators that may be useful in solving my issues.

Here is my connect file include:

$link = mysql_connect("localhost", "username", "password") or die("Invalid query: " . mysql_error());
mysql_select_db("tradeport", $link) or die("Database Connection Error: ".mysql_error());

Here is one of my queries:

$sSQL="SELECT mainPhone FROM admins";
$result21=mysql_query($sSQL) or die ("MySQL err: ".mysql_error()."<br>".$sSQL);

if($row21 = mysql_fetch_array($result21))
{$phoneMain = $row21['mainPhone'];}

Another note I would like to add is that when I began migration on this site all of the php was showing in the page source. I had to replace all php brackets with the more formal ones as shown here:

<? //before

<?php //after

I'm currently running PHP version 5.3.8 and MySQL version 5.0.92.

Any information would be greatly apreciated.

I've tried that and it gives me this error in return: SELECT command denied to user ''@'localhost' for table – Trig3rz 20 mins ago

Check that the database user is setup with the correct permissions GRANT SELECT ON db.* TO user@'localhost' IDENTIFIED BY 'pass';

You might want to check the php.ini file on the original server to see what differences there are. <? is php short tags and it is enabled in the php ini file with this line:

short_open_tag=On

Try adding the db name to the query

"SELECT mainPhone FROM tradeport.admins"

It is always good habit to reference your db connection in your mysql_* or mysqli_* (which you should be using) function calls.

Try:

$result21=mysql_query($sSQL, $link) or die ("MySQL err: ".mysql_error()."<br>".$sSQL);

You say your are seeing the error message, "No database selected", which makes me wonder if you are actually executing the mysql_select_db line of code because its error message is "Database Connection Error:", followed by the mysql error code.

Also, where is the include file getting the values for username and password? You just have quoted literal strings, which at first I assumed was for security purposes.

I think the code snippets you provided don't show us the whole picture.