...

View Full Version : mysql_result to mysqli ?



needsomehelp
02-01-2013, 05:42 PM
I have managed to convert all but a few of my files but just came across the largest file of all that has stacks of these sort of lines...


if (mysql_result($res, 0 ,'verified') == "Yes") {
}


what is the correct way to check the value of the results using mysqli ?




here is some more of the code...
i have changed the first part of the first IF but the rest is where i am failing.


$res = db_query($mysqli, $sql);
if(@$res->num_rows && @mysql_result($res, 0 ,'verified') == "Yes" && @mysql_result($res, 0 ,'suspended') == "No") {
if(@mysql_result($res, 0 ,'changeofpasswordcode') != "") {
$randomcode = @mysql_result($res, 0 ,'changeofpasswordcode');
} else { $randomcode = createPasswordResetCode();
}
// do something
}






i tried this but not getting very far.. EDITED


$res = db_query($mysqli, $sql);
if($res->num_rows &&
$res->fetch_object()->verified == "Yes"
&& $result->fetch_object()->suspended == "No") {
if($res->fetch_object()->changeofpasswordcode != "") {
$randomcode = $res->fetch_object()->changeofpasswordcode;
} else { $randomcode = createPasswordResetCode();
}
// do something
}

the line that kicks up a problem is


&& $result->fetch_object()->suspended == "No") {

showing...
Trying to get property of non-object




I think it is trying to advance to the next row when there are no more.


how do i read the same row ?

Fou-Lu
02-01-2013, 07:49 PM
Is that supposed to be $result or is it supposed to be $res?
It also cannot be used quite this way. A single call to a fetch function increments the resultset pointer to the next row. So each fetch would move the pointer one more row, which depending on the number of results would return null (which would throw the same error you have as well) when it hits the last record. You need to capture a single call to the fetch and then check that one for what it has within it.

There is no directly comparable function to mysql_result from what I can see. You need to fetch the record in its entirety and offset the returned array offset or object property to use it.

needsomehelp
02-01-2013, 08:37 PM
i ended up find this out to set a resOBJ string with the results in and then reuse the resOBJ string for my data.

are there any manuals that i can read up on mysqli. I have tried php.net but it is very limited on how you use it. it seems to show more of other ways to use the old mysql more than anything else.

i am starting to understand how this works. but i really want to learn a lot more, and although i appreciate all of your help and those of the other members I feel that i should really be reading up on this. I just dont know where to look ?

I am looking for a site that has a few examples of how each mysqli command works.

Fou-Lu
02-01-2013, 09:22 PM
Perhaps your looking in the wrong section of the manual. The pages you want can be found here: http://php.ca/manual/en/book.mysqli.php

needsomehelp
02-01-2013, 09:29 PM
yep, maybe so...

i did try that book! but it was not giving me many example of how the commands could be used. of course i do not expect every possible method but a few that can help us work the rest out.

i am more looking for information about the -> part, i sort of understand what it is doing, but think i need to read a lot more about it.

Fou-Lu
02-01-2013, 10:36 PM
-> is a dereference operator; it has nothing to do directly with MySQLi. That is used with objects. The object section of the API can help describe these: http://php.ca/manual/en/language.oop5.php
OOP is a completely different paradigm from procedural code. Logically it is simply a structure of variables and methods that operate individually on an instance of a class. So two objects can call the same methods, yet the operations within them are likely using different data. So think of it as a mini sandbox that you can play in.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum