Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

mysqli mysql array

  • Please log in to reply
2 replies to this topic

#1 schnautzr

schnautzr

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 12 December 2010 - 12:04 PM

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

  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 December 2010 - 12:15 PM

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();
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 schnautzr

schnautzr

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 12 December 2010 - 12:22 PM

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'];

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download