i wanna fetch just one row from my table using PHP mysqli. it uses prepared statement, but i can't do that and my code shows nothing. what should i do?
<?php
require_once 'inc/db.inc.php';
$post_id = $_GET['id'];
$q = "SELECT post_id, post_name, post_title, post_content, post_author, post_short_des, post_tag, post_date FROM posts WHERE post_id=? LIMIT 1";
$stmt = $conn->prepare($q);
$stmt->bind_param('i', $post_id);
$stmt->execute();
$stmt->bind_result($post_id, $post_name, $post_title, $post_content, $post_author, $post_short_des, $post_tag, $post_date);
$stmt->fetch();
print_r($stmt);
mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…")The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code.f($x, $y)procedural style becomes$x->f(y)in object-oriented form, the first argument is the object and how you call the function. The main thrust of OO is that you have functions that operate on an "object" instead of on arbitrary parameters. Think of an object as a container of related variables and functions that you can pass around ust as you would a simple variable.mysqliso far it's worth checking it out. The named placeholders feature is a big deal, plus you can pass an associative array toexecute()which makes the code a lot less fussy. Even better is an ORM like Doctrine, Propel, RedBeanPHP, or Eloquent which do a lot more than just run queries.