This topic is locked
[SOLVED]

 API PHP Code Generation

5/18/2020 8:15:02 AM
PHPRunner General questions
K
Kervee author

[size="5"]Hi Guys,
How can I refer or link a specific field from another table into my PHP code for my Rest API URL parameter so that everytime I change the data from that table, it will fetch the changes to the parameter URL on my API, I am using PostgreSQL as my database btw, can you enlighten me guys please, below is the screenshot and highlighted in red as to where I should want the specific data to show.
Many thanks in advance![/size]

Admin 5/18/2020

Not sure I understand. Where this code will go?

K
Kervee author 5/18/2020



Not sure I understand. Where this code will go?


These codes are actually a request code to get data from another website, in simple term, I just want to autofill the below boxes (see screenshot), and the data should be from a table

Admin 5/18/2020

I see what you saying. Take a look at this:

https://xlinesoft.com/phprunner/docs/db_query.htm
You can execute your SQL Query in the beginning, retrieve your data and then use $data["FieldName"] in the code as the manual explains.

K
Kervee author 5/19/2020



I see what you saying. Take a look at this:

https://xlinesoft.com/phprunner/docs/db_query.htm
You can execute your SQL Query in the beginning, retrieve your data and then use $data["FieldName"] in the code as the manual explains.


When I try to execute the code structure you mentioned, it gives me an error saying Fatal error: Call to a member function fetchAssoc() on boolean in (path of page) on line 150
is this the right way to do it? please see below screenshot, need your help guys

M
MikeT 5/19/2020

Something's probably wrong with your query, did you check it by just running the sql agains't the db? And for the thing you're trying to do you'd want to use a query that only returns 1 row, no?

(and some code to decide what to do if no result is returned).

K
Kervee author 5/19/2020



Something's probably wrong with your query, did you check it by just running the sql agains't the db? And for the thing you're trying to do you'd want to use a query that only returns 1 row, no?

(and some code to decide what to do if no result is returned).


Hi Michael, yes I tested the SQL query and its working fine, this is for a few rows, can you share some example how I can make it to do something if the result is no
thanks

M
MikeT 5/20/2020

I can't say much from here.
The error you mentioned probably means that the DB:: method returned false because it didn't return any results. And that indicates that the query is not correctly formulated.

And as I understand your problem: you don't want a few rows but the fields of 1 row. Otherwise you'd have to iterate over the results.
If you store these parameters in a table you'd want to use some kind of limit parameter so that just 1 record is returned, at least if the table can contain >1 row.

M
macalister 5/20/2020



When I try to execute the code structure you mentioned, it gives me an error saying Fatal error: Call to a member function fetchAssoc() on boolean in (path of page) on line 150
is this the right way to do it? please see below screenshot, need your help guys



Hi
The error "Fatal error: Call to a member function fetchAssoc() on boolean" generally is because you have an error in your query.
You can try using db_fetch_array function for testing query to see the sql errors. I use this function to test in MySQL i dont know if in PostgreSQL works



$sql = "select * from public.parameters";
$res = db_query($sql);
$data = db_fetch_array($res);


Note: in the phprunner manual recommends using the DB:Query() function from Database API (db_fetch_array function is deprecated).

K
Kervee author 5/21/2020



Hi
The error "Fatal error: Call to a member function fetchAssoc() on boolean" generally is because you have an error in your query.
You can try using db_fetch_array function for testing query to see the sql errors. I use this function to test in MySQL i dont know if in PostgreSQL works



$sql = "select * from public.parameters";
$res = db_query($sql);
$data = db_fetch_array($res);


Note: in the phprunner manual recommends using the DB:Query() function from Database API (db_fetch_array function is deprecated).


Hello, thanks for the reply
it seemed that the sql query i have is working using the code you suggest, but the weird thing is, it shows up the data i want but at the same time, there was an error showing up, see below screenshots