aspose file tools*
The moose likes PHP and the fly likes  Object of class mysqli_result could not be converted to string/int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark " Object of class mysqli_result could not be converted to string/int" Watch " Object of class mysqli_result could not be converted to string/int" New topic
Author

Object of class mysqli_result could not be converted to string/int

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 319

In my table ,i have a field called base_pay with type int(11).

When i retrieve the base_pay of a employee and try to add or multiply the base_pay.
Here are my queries


$result = mysqli_query($con,"SELECT base_pay FROM guest where name='Mahtab'");
mysqli_query($con,"UPDATE guest SET net_pay='$result*15"
WHERE name='Mahtab'");

It says Catchable fatal error: Object of class mysqli_result could not be converted to string

Does it mean that the return type of query is not int.

If not then how to do some mathematics on an int field retrieved from table.


http://www.mahtabalam.net , Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

That is correct, a mysql_result cannot be converted into an integer; instead a mysql_result is a handle for a collection of data that you have to get a row at a time. So what you need to do is extract the integer from the mysql_result, like this:

$row = mysql_fetch_row($result);
$base_pay = $row[0];

There are other ways to do this also. Try looking up a PHP with MySQL turorial.
Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 319

Thank You , I get it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object of class mysqli_result could not be converted to string/int