php-crud-api: Stopped working after changing database
First of all, thank you very much! Great project!
I get a weird behavior, using MariaDB and PHP 7.2
At first, I got code:1000, then I created a pippo
table in a records
database, following another past issue on this project, and it worked, I got the JSON object by viisting http://0.0.0.0/api.php/records/pippo/
Then I changed api.php database (same user) to another existing database and it failed.
Then I got back to records, and it failed. First it threw 9999, with debug true, I could see the error code was 2002 But I didn’t noted it.
And now, I get code:1000
This container is running another php stuff (tikiwiki test). I wonder if it’s related.
I only changed api.php credentials and added your code from another issue:
if (!preg_match('|^/([^/]*)(/.*)|', $_SERVER['PATH_INFO'], $matches)) {
die('database not found');
}
$database = $matches[1];
$_SERVER['PATH_INFO'] = $matches[2];
I restarted the container without luck.
pippo table is present. Adminer is on it (I have issue with your other admin script, so adminer to the rescue):
I’m not php saavy. Please bear with me 😃 Thank you!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 27 (10 by maintainers)
Now I’ll post to the wiki project and will propose them to integrate your project to get a restful API within tikiwiki 😃 It’s due for the next version.
Ah! I was confused. I thought it was dynamic and the records database was for testing purpose. I understand. So using your code and replacing records with
If you’re ok with that.
Sorry, posted too fast. It makes sense to keep the database within the php, not exposing it through GET. I’ll stay with static and use records.
Thank you so much for your help.
{“code”:1000,“message”:“Route ‘/tikiwiki21/records/users_users’ not found”}
Ok, let’s leave the IP thing on the side for now.
I change the database and get code 1000:
http://0.0.0.0/api.php/tikiwiki21/users_users
{“code”:1000,“message”:“Route ‘/tikiwiki21/users_users’ not found”} with ‘address’ => ‘172.26.0.2’, ‘database’ => ‘tikiwiki21’, Apache log: 172.26.0.1 - - [18/May/2020:13:34:11 +0000] “GET /api.php/tikiwiki21/users_users HTTP/1.1” 404 313 “-” “Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36”while it’s available for my user on Adminer:
Thank you for the link. Though, I don’t get all the subtleties here. Does it mean, I must tweak the MariaDB container settings for api.php? It worked for a brief period with localhost or 0.0.0.0 (I don’t remember). Now it must be the real IP on docker network. What should I do to make it work and keep the right settings for the wiki? I wonder how adminer and the wiki seam to work as is.
I can’t force a fixed IP using docker-compose as in https://stackoverflow.com/questions/39493490/provide-static-ip-to-docker-containers-via-docker-compose:
Found a temporary fix. When I change to
'address' => '172.26.0.2',
(the MariaDB container) in api.php config, it works on the wiki container:It makes sense. But it worked for a brief time without this setting. And Adminer finds its way between containers to connect dynamically to the MariaDB container. What could be done to help api.php to resolve the container ip based on the port?
Sure! Thank you for helping me
From the apache log:
Ok:
I removed your code to get closer to when it was working and I tried within the container:
Thank you Maurits. You’re fast! I set the PC on sleep for lunch. Now, I changed to
http://localhost/api.php/db/records/pippo/
and I get the 9999 error again, with the 2002 error (no such file or directory):