Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2013, 05:42 PM   PM User | #1
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 307
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
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..
needsomehelp is offline   Reply With Quote
Old 02-01-2013, 07:49 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-01-2013, 08:37 PM   PM User | #3
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 307
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
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.
needsomehelp is offline   Reply With Quote
Old 02-01-2013, 09:22 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-01-2013, 09:29 PM   PM User | #5
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 307
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
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.
needsomehelp is offline   Reply With Quote
Old 02-01-2013, 10:36 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
-> 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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:28 AM.


Advertisement
Log in to turn off these ads.