Answer the question
In order to leave comments, you need to log in
Why does the function return NULL instead of an array?
index.php :
<?php
require 'db.php';
require 'function.php';
#DATABASE CONNECT;
$testConnect = new dbConnect('test');
$testConnect->dbConnect();
#TEST QUERY
//PARAMETERS:
$queryConstruct = $testConnect->dbConnect();
$query = "SELECT * FROM qwert WHERE id = 1";
$fetchType = 'fetch_row()';
//ACTION:
fetchQuery($queryConstruct, $query, $fetchType); #Должна вернуть $sql массив с выборкой из БД;
?>
<?php
require 'index.view.php';
?>
<?php
function fetchQuery($construct, $query, $fetchType) {
$sql = $construct->query('{$query}')->$fetchType;
return $sql;
}
?>
Answer the question
In order to leave comments, you need to log in
$fetchType = 'fetch_row()';
Replace with
Replace with$sql = $construct->query($query)->$fetchType();
To expand a variable, quotes must be double:
In general, a simple variable is enough:$sql = $construct->query($query)->$fetchType;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question