6

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

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:

<?php
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:

<?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");


?>
Community
  • 1
  • 1
ipengineer
  • 3,107
  • 7
  • 33
  • 37

4 Answers4

8

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); 
Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
2

You have to execute the query before you can fetch results:

$searchroute = "SELECT *  ...";
$results = mysql_query($searchroute);
$row = mysql_fetch_row($results);
Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
0

mysql_fetch_row must be called after mysql_query, you can't pass the query into the fetch row - see PHP Manual

Nick Shaw
  • 2,083
  • 19
  • 27
0
$db = new MySQL(true, DB_DATABASE_ROUTING, DB_SERVER, DB_USER , DB_PASS);

is that supposedto be MySQLi? The mysql_*() functions do not have an OOP interface. You'd be mising mysqli and mysql calls, which is not supported. They're completely independent of each other internally, and a db handle or result statement from one is NOT useable in the other.

Marc B
  • 356,200
  • 43
  • 426
  • 500