Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts

    mysql_result to mysqli ?

    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...
    Code:
    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.
    Code:
    $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
    Code:
    $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
    Code:
    && $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 ?
    Last edited by needsomehelp; 02-01-2013 at 06:47 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    -> 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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •