Jump to content

Mysqli question


Locked

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.