mysql - PHP query class not returing values -


I am writing a query class for my php project, but I have a problem that query any value from my db Does not return.

PHP Code:

  & lt ;? Php class database connect {secure $ host = 'localhost'; Protected $ user = 'root'; Protected $ pass = 'root'; Protected $ db = 'test'; Public function __ composition () {$ con = mysqli_connect ($ this-> host, $ this- & gt; user, $ this-> pass, $ this- & gt; db) or die ('from db Can not be connected); Return $ Conn.; }} Class ExecuteQuery {public $ connection; Public $ results; Public function __construct () {$ this- & gt; Connection = new DatabaseConnect (); } Public function getQueryAction ($ sql) {$ this- & gt; Result = mysqli_query ($ this-> connection, $ sql); } Public Function SetString Action ($ string) {$ file = file_get_contents ('queryFile.json'); $ Json = json_decode ($ file, true); Forex Currency ($ json ['query'] $ this-> as a result) {return $ -> $ [$ string]; }}} $ Execute = new ExecuteQuery ();  

Jason file ('All questions will contain'):

  {"queries": [{"query1": "SELECT * FROM tbl_user" }, {"Query2": "SELECT * FROM tbl_users WHERE status = 1"}}}  

Index file:

  & lt; Php require_once ('query.php'); ? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H1 & gt; Welcome to & lt; / H1> & Lt; H3 & gt; & Lt ;? Php $ execute- & gt; GetQueryAction ($ execute-> set string action ('query1')); Foreign exchange ($ execution-> result as $ item) {echo $ item ['id'] '' $ Item ['user_name'] '& Lt; Br /> ';; }? & Gt; & Lt; / H3 & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

So what I do, Jason prepares a class to process the file and uses the class to run a query. As I have mentioned in Jason File, keeps all the questions, in the index and in any file where I include query.php, I can run all the questions like this:

  $ execute-> GetQueryAction ($ execute -> Set string action ('query name'));  

After some debugging I realized that the code fails in the getQueryAction method, I think mysqli_query is not like the $--> connection.

My questions are:

Why and how to fix it

A producer can not return anything, only the purpose of a creator is to create an example of a square

  private $ conn; Public function __ composition () {$ this- & gt; Con = mysqli_connect ($ this-> host, $ this- & gt; user, $ this-> pass, $ this- & gt; db) or die ('can not connect db'); } Public function get_connection () {return $ this-> Con; }  

In the ExecuteQuery class you can:

  public function __construct () {$ db = new DatabaseConnect () ); $ This- & gt; Connection = $ db- & gt; Get_connection (); }  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -