S
S
Sandr-02020-02-11 12:13:03
PHP
Sandr-0, 2020-02-11 12:13:03

How to organize the storage of a temporary data table in php for the duration of the script?

I am writing an exchange for a site with an external service. I write on the side of the site, to the service only requests for its API. Each entity that is exchanged has:
1) id on the site (mysite_id)
2) external id on the site (mysite_ext_id)
3) external id on the external service (service_ext_id)
4) id on the external service. (service_id)
During the execution of the script, I need to quickly record the correspondence of one value to another, so that I can use it later.
In terms of data structure, this is similar to a table whose columns (4 of these id) are gradually filled during execution. And for each of its lines, I need to be able to get the corresponding mysite_id by the service_ext_id value, the corresponding service_id by the service_ext_id value, and so on.

I do not know how best to organize the storage of such information. Now all this is written into a bunch of associative arrays like [service_ext_id1 => mysite_id1, service_ext_id2 => mysite_id2, ...]. And there are a lot of methods for accessing this info like getServiceIdByMysiteId, getServiceIdByServiceExtId, getMysiteIdByServiceExtId, etc.

There seems to be no need for a separate table in the database, because information exists and is used only while the script is being executed, then it will become irrelevant. And there would be a lot of requests to this table at runtime.

I would like to structure and normally organize the storage in RAM and access r of information that has the format of a table. And then also pass all the information received to other methods. What would be the most logical way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-02-11
@Sandr-0

I want to structure and properly organize storage in RAM

Well, actually, here is the answer to the question.
Any key-value values ​​\u200b\u200bare not suitable for us, but a rectangular table is very even.
Considering that relational databases allow tables to be stored in memory, the problem is solved. Mysql would be overkill here, but sqlite would be fine.
$db = new PDO('sqlite::memory:');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$db->query("CREATE TABLE temp (mysite_id int,mysite_ext_id int,service_ext_id int,service_id int)");

well, then with the usual requests
$db->query("INSERT into temp (mysite_id) values (1)");
var_dump($db->query("SELECT service_ext_id FROM temp where mysite_id=1")->fetchColumn());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question