firstly I'd suggest you ditch the pconnect routine in favor of a simple mysql_connect.
Here's my take on it. The query looks fine and yet it is failing. So you need to know why it is failing. obviously, one f the elements of your query is innaccurate or incomplete.
Personally, I prefer to use CAPS ON for sql commands (SELECT WHERE etc) and make all field names lowercase as it makes the sql's easier to reead (but that is an aside.
try my modified version (I've ommited one of the checks, but you can always put it back in later.
$dbhost = 'localhost';
$dbusername = 'user';
$dbpw = 'password';
$dbname = 'database1';
$db = mysql_connect($dbhost , $dbusername , $dbpw);
@mysql_select_db("$dbname",$db);
$query = "SELECT * FROM contacts";
$result = mysql_query("$query", $db);
$num_results = mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
Before you proceed, make absolutely certain that your CaPS aRe CoRrecT for table names, paswords etc.