Sunday 25 December 2016

php - Warning: mysql_fetch_row() expects parameter 1 to be resource











I am receiving the below message when I run this script:



Warning: mysql_fetch_row() expects parameter 1 to be resource, string given in /var/www/html/toolkit/routing.php on line 12



I have ran the query in the mysql console and it prints the correct row. Not sure why I cant get it to show up in php?



routing.php page:




error_reporting(E_ALL);
////error_reporting(0);
ini_set('display_errors', 'On');
include("db/sbc_config.php");
include("db/mysql.class.php");
$db = new MySQL(true, DB_DATABASE_ROUTING, DB_SERVER, DB_USER , DB_PASS);
if ($db->Error()) $db->Kill();

$searchroute = "SELECT * FROM destination_route as d WHERE d.destPrefix='2146811'";


$result = mysql_fetch_row($searchroute);
echo $result;

?>


sbc_config.php:



//database server

define('DB_SERVER', "10.10.1.146");

//database login name"
define('DB_USER', "user");

//database login password
define('DB_PASS', "pasword");

//database names
define('DB_DATABASE_ROUTING', "routing");


//smart to define your table names also
define('TABLE_DESTINATION_ROUTE', "destination_route");


?>

Answer



mysql_fetch_row takes a cursor and returns the next row in that cursor. You're trying to give it a string. You're missing a step.




You'll have to execute that query first:



$cursor = mysql_query($searchroute); // for example
$result = mysql_fetch_row($cursor);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...