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): adminer 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)

Most upvoted comments

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: 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:

Creating network "tiki_vpcbr" with driver "bridge"
ERROR: Pool overlaps with other one on this address space

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: workingdb

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

curl -i http://172.26.0.4/api.php/records/pippo/
HTTP/1.1 500 Internal Server Error
Date: Mon, 18 May 2020 12:58:52 GMT
Server: Apache/2.4.38 (Debian)
X-Powered-By: PHP/7.2.27
Content-Length: 13
X-Exception-Name: PDOException
X-Exception-Message: SQLSTATE[HY000] [2002] No such file or directory
X-Exception-File: /var/www/html/api.php:6283
Connection: close
Content-Type: application/json; charset=utf-8

From the apache log:

{"log":"[Mon May 18 12:43:09.793764 2020] [authz_core:error] [pid 32] [client 127.0.0.1:43452] AH01630: client denied by server configuration: /var/www/html/db/records\n","stream":"stderr","time":"2020-05-18T12:43:09.793817934Z"}
{"log":"127.0.0.1 - - [18/May/2020:12:43:09 +0000] \"GET /api.php/db/records/pippo/ HTTP/1.1\" 404 310 \"-\" \"Wget/1.20.1 (linux-gnu)\"\n","stream":"stdout","time":"2020-05-18T12:43:09.814195642Z"}

Ok:

root@d622e0261ba1:/var/www/html# wget http://127.0.0.1/api.php/records/pippo/ -O /tmp/pippo
--2020-05-18 12:42:16--  http://127.0.0.1/api.php/records/pippo/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2020-05-18 12:42:16 ERROR 500: Internal Server Error.

I removed your code to get closer to when it was working and I tried within the container:

root@d622e0261ba1:/var/www/html# wget http://localhost/api.php/records/pippo/ -O /tmp/pippo
--2020-05-18 12:31:51--  http://localhost/api.php/records/pippo/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2020-05-18 12:31:51 ERROR 500: Internal Server Error.

root@d622e0261ba1:/var/www/html# wget http://localhost/api.php/db/records/pippo/ -O /tmp/pippo
--2020-05-18 12:32:15--  http://localhost/api.php/db/records/pippo/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2020-05-18 12:32:15 ERROR 404: Not Found.

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): crudapi

     'driver' => 'mysql',
     'address' => 'localhost',
        'username' => 'myusername',
        'password' => 'mypass',
        'database' => $database,
     'debug' => true