Answer the question
In order to leave comments, you need to log in
How to properly optimize the work of php and mysql with two databases?
I am writing a billing system for a small Internet provider. Due to certain reasons, processing of subscribers requires data from two databases at once.
I did like this:
array(16000) {
'0689182' =>
array(19) {
'id' =>
string(5) "25491"
'agrm_id' =>
...
'vg_id' =>
string(8) "1323"
'rec' =>
string(1) "0"
}
...
}
foreach($basesData as $user) {
$strAgrmId .= $user['agrm_id'] . ',';
}
$sql = "SELECT
number,
balance,
credit
FROM
agreements
WHERE agrm_id IN(" . substr($strAgrmId, 0, -1) . ")";
array(16000) {
'0689182' =>
array(19) {
'balance' =>
string(5) "25491"
'credit' =>
string(1) "0"
}
...
}
foreach($basesData as $key => $user) {
$users[$key] = array_merge($basesData[$key], $agrmData[$key]);
}
foreach($users as $key => $user) {
..code..
foreach($arrayPool as $one) {
..code..
$users[$key]['status'] = $one['status'];
}
}
Answer the question
In order to leave comments, you need to log in
You can also access two databases in one query if the user has access - dbName.dbTable.dbField
stackoverflow.com/questions/4076562/query-with-joi...
I don’t know your level of knowledge, so just in case I’ll ask again: exactly two different databases or just tables? These two things are sometimes confused.
Profile where you are actually wasting your time. The current zend engine has a rather strange memory management, which will be thoroughly optimized in php7, but merging only 16 thousand records is a garbage question as long as there is enough memory.
You can somehow twist the processing logic upside down - but for this you need to understand what needs to be done in the end (at the same time, it will be lazy to read long essays).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question