Monday, 15 June 2015

php - MySQLi - Right way to execute querys? -



php - MySQLi - Right way to execute querys? -

first of all, first meeting mysqli... heard mysqli better, every time wrote code,

fatal error: phone call fellow member function bind_param() on non-object

my code this:

<?php /* create new mysqli object database connection parameters */ $m = new mysqli('localhost', 'root', '', 'mysqlisample'); if(mysqli_connect_errno()) { echo "connection failed: " . mysqli_connect_errno(); exit(); } $ida=1; $statement = $m->prepare("select * post `id` = ?"); $statement->bind_param("i",$ida); $id = 0; $post_title = ''; $post_content = ''; $statement->bind_result($id,$post_title,$post_content); $statement->execute(); while ($statement->fetch()){ echo $id.' '.$post_title.' '.$post_content.'\n'; //these variables values of current row } ?>

this 1 of many code sample read somewhere, but, none of them working...

my question is

what right way executing mysqli query , print results?

for every project made, utilize mysql_* unsafe.

please, give me example, or nice tutorial, because can't understand mysqli...

i sorry if question duplicate (maybe), need specific answer.

the problem $statement->bind_param("i",$ida); returns false, can't phone call method bind_param on false

see: http://php.net/manual/de/mysqli.prepare.php

try:

mysqli_stmt_bind_param($statement, "i", $ida);

instead of:

$statement->bind_param("i",$ida);

php mysqli

No comments:

Post a Comment