Jump to content

RESOLVED: mysql_fetch_array() expects parameter 1 to be resource, object given

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
schnautzr

schnautzr

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

I spent several hours looking for an answer to this and have read dozens of threads, but they all seem to be case-specific-- none of the solutions I've found so far have helped me.

For the sake of simplicity, I'll omit variable declarations and such and just show you the actual string values. It'll be easier on the eyes and more compact, plus it puts it into context.

<?php

$DBConnect = @mysqli_connect("localhost", "root", "");

mysqli_select_db($DBConnect, "survey");

$QueryResult = @mysqli_query($DBConnect,

	"SELECT password FROM clients WHERE username = \"schnautzr\"");


echo mysql_fetch_array($QueryResult);

//Warning: mysql_fetch_array() expects parameter 1 to be resource, object given

?>

All I'm trying to do is display the single value in the column "password" as a string-- if I can at least manipulate it as a string value then I should be able to compare it to another string. The database connection is good, the query functions perfectly (I tested it in the command prompt and in the PHP), but the echo statement simply won't work.

I assume someone around here can spot the flaw. Thanks in advance!

Edited by schnautzr, 12 December 2010 - 12:24 PM.
resolved


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you're using mysqli at connect, but not at fetch array. change to mysqli_fetch_array and it will work better.
the other way is to use it object oriented, $QueryResult->fetch_array();
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
schnautzr

schnautzr

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks, that helps. It looks like my biggest issue was that in all the trying I did last night, I never fixed a typo that even persisted when I entered it into this post-- I said "mysql" instead of "mysqli".

Just in case anyone happens upon this thread in the future while looking for an answer, here's what worked:
$Row = (mysqli_fetch_assoc($QueryResult));

echo $Row['password'];