M
M
Mixelv2014-04-11 14:47:30
PHP
Mixelv, 2014-04-11 14:47:30

Mysqli - how to fix error with bind_param?

$q="Проверка";
$query = $link->prepare("SELECT id, name FROM cities WHERE name LIKE CONCAT(?,'%')");
$query->bind_param('s',$q);
$query->execute();
$res = $query->get_result();

Gives an error: "Fatal error: Call to a member function bind_param() on a non-object"
The error, respectively, points to the line with bind_param...
Request
SELECT id, name
FROM cities
WHERE name LIKE CONCAT( 'Мос', '%' )

Through phpMyAdmin it works correctly.
Throw out bind and pass an array with the value in$query->execute(array($q));
$query = $link->prepare("SELECT id, name FROM cities WHERE name LIKE CONCAT('?','%')");
//$query->bind_param('s',$q);
//$query->execute();
$query->execute(array($q));
$res = $query->get_result();

doesn't help, gives error
Fatal error: Call to a member function execute() on a non-
object

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanatPHP, 2014-04-29
@FanatPHP

Before connecting to mysqli, we write a magic line
and find out what the problem was with our request

1
1001001 111, 2014-04-11
@IgorO2

try to write like this, $query->execute($q);

V
veontomo, 2014-04-11
@veontomo

Your variable is most likely false, not an object as you would expect: www.php.net/manual/en/mysqli.prepare.php . And false has no methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question