Jump to content

mysqli_stmt->bind_result($attr1, $attr2) :: not working


pedromas

Recommended Posts

Hi everyone,

 

I am currently having a problem with phpDesigner. Whenever I use the mysqli_stmt->bind_result() it gives me the following error:

Number of bind variables doesn't match number of fields in prepared statement.

 

Underneath I have a simple php code where this happens.

Do you know why this might be happening?

 

Any help is highly appreciated.

 

<?php

//Start connection

$mysqli = new mysqli( 'localhost',

'user',

'pass',

'db');

if(!$mysqli)

{

die('A connection to the database was not possible!');

}

if($mysqli_stmt = $mysqli->stmt_init())

{

//Prepared instructions

$sql = 'SELECT*FROM destinations WHERE id = ? ';

$sql .='AND city != ?';

 

$string = 'Berlin';

$integer = 3;

$mysqli_stmt->prepare($sql);

$mysqli_stmt->bind_param('si', $string,$integer);

$mysqli_stmt->execute();

 

//Error

if($mysqli_stmt->errno)

{

echo 'Fehler ('.$mysqli_stmt->errno.'): '.$mysqli_stmt->error;

}

if($mysqli_stmt->result_metadata())

{

$mysqli_stmt->store_result();

echo 'Datasaetzen: '.$mysqli_stmt->num_rows.'<br />';

//recall result

$attr1='';

$attr2='';

$mysqli_stmt->bind_result($attr1,$attr2);

while($mysqli_stmt->fetch())

{

echo $attr1.' | '.$attr2.'<br />';

}

}

else

{

echo 'Datensaetze: '.$mysqli_stmt->affected_rows.'<br />';

}

$mysqli_stmt->close();

 

 

}

else

{

die('It was not possible to generate the object!');

}

$mysqli->close();

?>

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.