When i shifted my working code from local to my dedicated host, none of the query is working, however I am able to connect to the database. I know it should be something trivial but i am unable to work it out since last hour.
Here is my code:
<?php
set_time_limit(0);
$DbCon = mysql_connect('localhost:1023','username','password');
mysql_select_db('dbname', $DbCon);
if (!$DbCon)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo("wait...\n");
echo("Caching name...\n");
$query0="SELECT * FROM sometablename2";
$Result0 = mysql_query($query0,$DbCon);
$anarray=array();
$anotherarray=array();
while($records0 = mysql_fetch_array($Result0))
{
do something
}
}
The Output i get is :
wait…
Caching name…
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /path/to/php/file/code.php on line 42
PHP Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in /path/to/php/file/code.php on line 56
So, it’s clear that I am able to connect to database but no output from this query. I have run the same query in the database and it is working.
Any directions will be very helpful.
Use the mysql_error function to find out what’s wrong.
Edit: as per comment below, also try, for example: