How to return result from mysqli stmt prepare and bind_param statement.
Please note that you must install MySQL Native Driver (mysqlnd) driver to use get_result();
DBClient.php
<?php
//error_reporting(E_ALL ^ E_DEPRECATED);
class DBClient {
var $host,$db,$user,$pass;
var $mysqli,$isDBConnect;
function __construct() {
$this->host = "localhost";
$this->db = "mydb";
$this->user = "root";
$this->pass = "pass";
try {
$this->mysqli = new mysqli($this->host, $this->user, $this->pass,$this->db );
if ($this->mysqli->connect_error) {
die('Error : ('. $this->mysqli->connect_errno .') '. $this->mysqli->connect_error);
}
} catch(Exception $ee) {
$this->link=false;
$this->isDBConnect=false;
}
}
public function autocommit_false() {
$this->mysqli->autocommit(FALSE);
}
public function commit() {
$this->mysqli->commit();
}
public function rollback() {
$this->mysqli->rollback();
}
public function close() {
$this->mysqli->close();
}
}
?>
Part_Wise_Class.php
<?php
class Part_Wise_Class {
public function part_wise_get_part_nm($class_id,$subject_id) {
$ssql = "SELECT part_id,part_nm from part_info WHERE class_id =? and subject_id=?";
$db=new DBClient();
$stmt = $db->mysqli->stmt_init();
$stmt = $db->mysqli->prepare($ssql);
$stmt->bind_param("ii",$class_id,$subject_id);
$stmt->execute();
$result = $stmt->get_result();
$db->close();
return $result;
}
}
?>
test.php
<?php
include_once("DBClient.php");
include_once("Part_Wise_Class.php");
$part_wise=new Part_Wise_Class();
$class_id=$_GET['class_id'];
$subject_id=$_GET['subject_id'];
$result=$part_wise->part_wise_get_part_nm($class_id,$subject_id);
$rows = array();
while ($row = $result->fetch_array(MYSQLI_BOTH)) {
echo $row['part_id'];
}
?>
Please note that you must install MySQL Native Driver (mysqlnd) driver to use get_result();
DBClient.php
<?php
//error_reporting(E_ALL ^ E_DEPRECATED);
class DBClient {
var $host,$db,$user,$pass;
var $mysqli,$isDBConnect;
function __construct() {
$this->host = "localhost";
$this->db = "mydb";
$this->user = "root";
$this->pass = "pass";
try {
$this->mysqli = new mysqli($this->host, $this->user, $this->pass,$this->db );
if ($this->mysqli->connect_error) {
die('Error : ('. $this->mysqli->connect_errno .') '. $this->mysqli->connect_error);
}
} catch(Exception $ee) {
$this->link=false;
$this->isDBConnect=false;
}
}
public function autocommit_false() {
$this->mysqli->autocommit(FALSE);
}
public function commit() {
$this->mysqli->commit();
}
public function rollback() {
$this->mysqli->rollback();
}
public function close() {
$this->mysqli->close();
}
}
?>
Part_Wise_Class.php
<?php
class Part_Wise_Class {
public function part_wise_get_part_nm($class_id,$subject_id) {
$ssql = "SELECT part_id,part_nm from part_info WHERE class_id =? and subject_id=?";
$db=new DBClient();
$stmt = $db->mysqli->stmt_init();
$stmt = $db->mysqli->prepare($ssql);
$stmt->bind_param("ii",$class_id,$subject_id);
$stmt->execute();
$result = $stmt->get_result();
$db->close();
return $result;
}
}
?>
test.php
<?php
include_once("DBClient.php");
include_once("Part_Wise_Class.php");
$part_wise=new Part_Wise_Class();
$class_id=$_GET['class_id'];
$subject_id=$_GET['subject_id'];
$result=$part_wise->part_wise_get_part_nm($class_id,$subject_id);
$rows = array();
while ($row = $result->fetch_array(MYSQLI_BOTH)) {
echo $row['part_id'];
}
?>
0 comments:
Post a Comment