Jump to content

Recommended Posts

	global $mysqli;
	$stmt = $mysqli->prepare('SELECT user_name from `user_details` where user_email = ?');
	$stmt->bind_param('s', $var);
	$stmt->execute() or $this->myerror[] = $stmt->error;		
	echo $stmt->affected_rows;

 

$stmt->affected_rows returns '-1' which would indicate a error but i dont see why it would error (Just started learning mysqli)

Link to comment
https://forums.phpfreaks.com/topic/183489-mysqli-question/
Share on other sites

For SELECT statements mysqli_affected_rows() works like mysqli_num_rows().

 

Connection

<?php
$mysqli = new mysqli("localhost","",,"");
if(mysqli_connect_errno() > 0)
{
	printf("Connection detail: %s.\n", mysqli_connect_error());
	exit();
}
$mysqli->autocommit(0);
global $mysqli;
?>

 

Other file

include ("_connect.php");
public $myerror = array();
function check_name($var)
{
	global $mysqli;
	$stmt = $mysqli->prepare('SELECT user_name from `user_details` where user_email = ?');
	$stmt->bind_param('s', $var);
	$stmt->execute() or $this->myerror[] = $stmt->error;		
	echo $stmt->affected_rows;
	if ($stmt->affected_rows > 0) {
		$this->myerror[] = 'This email is already in use.';
	}
	(count($this->myerror) > 0) ? $return = TRUE : $return = FALSE;
	print_r($this->myerror);
	$stmt->close();
	return $return;
}

 

myerror only returns array()

Link to comment
https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968552
Share on other sites

Except that you are using prepared statements and you are not using mysqli->affected_rows and any definition found in the manual concerning mysqli->affected_rows does not apply to prepared statements. You are using $stmt->affected_rows and it does not do what you think for a SELECT query.

Link to comment
https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968558
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.