I can't seem to get a response from my query method. I have a database connection from method ping_server and use mysqli as connector. Can anyone help me figure out why I cannot print results from mysqli_fetch_array.
dbclass.php
class db
{
private $connection;
private $selectdb;
private $lastQuery;
private $config;
function __construct($config)
{
$this->dbConfig = $config;
}
function __destruct()
{
}
public function openConn()
{
try
{
if($this->dbConfig->connector == "mysqli")
{
$this->connection = mysqli_connect($this->dbConfig->hostname, $this->dbConfig->username, $this->dbConfig->password);
$this->selectdb = mysqli_select_db($this->dbConfig->database,$this->connection);
}
}
catch(exception $e)
{
echo'Caught Exception:', $e->getMessage(), "\n";
}
}
public function closeConn()
{
try
{
if($this->dbConfig->connector == "mysqli")
{
mysqli_close($this->connection);
}
}
catch(exception $e)
{
echo'Caught Exception:', $e->getMessage(), "\n";
}
}
public function query($query)
{
//$query = str_replace("}", "", $query);
//$query = str_replace("{", $this->dbConfig->prefix, $query);
try
{
if(empty($this->connection))
{
$this->openConn();
$this->lastQuery = mysqli_query($this->connection, $query);
$this->closeConn();
return $this->lastQuery;
}
else
{
echo '2nd';
$this->lastQuery = mysqli_query($this->connection, $query);
// $this->closeConn();
echo $lastQuery;
return $this->lastQuery;
}
}
catch(exception $e)
{
echo'Caught Exception:', $e->getMessage(), "\n";
}
}
#get last query
public function lastQuery()
{
return $this->lastQuery;
}
#check to see if we have a connection
public function pingServer()
{
try
{
if($this->dbConfig->connector == "mysqli")
{
if(!mysqli_ping($this->connection))
{
return false;
}
else
{
return true;
}
}
}
catch(exception $e)
{
echo'Caught Exception:', $e->getMessage(), "\n";
}
}
public function fetchArray($result)
{
try
{
if($this->dbConfig->connector == "mysqli")
{
return mysqli_fetch_array($result,MYSQL_ASSOC);
}
else
{
return mysqli_fetch_array($result,MYSQL_ASSOC);
}
}
catch(exception $e)
{
echo'Caught Exception:', $e->getMessage(), "\n";
}
}
}
dbfile.php
<?php
include ('dbclass.php');
#dbConfig object with database data
$config = new dbConfig("hostname","username","password","table","mysqli");
$db = new db($config);
$db->openConn();
$test = $db->pingServer();
echo "Result of Ping: " . $test . '<br>';
$qry = "select project from PROJECTS_PROJECT where project='ab1234'";
$sql = $db->query($qry);
$db->lastQuery();
$result = $db->fetchArray($sql);
$db->lastQuery();
$db->closeConn();
?>