Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to db in handler #919

Open
kkrell2016 opened this issue Oct 3, 2022 · 4 comments
Open

Access to db in handler #919

kkrell2016 opened this issue Oct 3, 2022 · 4 comments
Assignees

Comments

@kkrell2016
Copy link

Hi, I'm not really a PHP guru.
I would like to check if a field called "oid" is currently null while updating. If the actual value in the DB is null, an update should be possible, otherwise no update should be made.

I think the validation handler would be the right place for this. My problem is how to access the database from the handler?
Can I reuse any function without opening a complete new connection to the db?

Or should I put it in another place? If so where?

Hope you can help me.

@mevdschee
Copy link
Owner

Hi, this seems like a duplicate of #751.

@mevdschee mevdschee self-assigned this Oct 4, 2022
@kkrell2016
Copy link
Author

Hi, this seems like a duplicate of #751.

Thank you for the hint, will have a look at the solution.
I think the idea from pat123456 is a good one, to define the handlers outside of the config section. But it may be a huge rewrite for you? Would just be a clean solution without the need to other modifications.
Yesterday I just made a quick&dirty workaround with a get_file_content to the same object I want to modify :)

Anyway, thanks for the quick response

@mevdschee
Copy link
Owner

But it may be a huge rewrite for you?

Yeah, that will be some work... and there is another solution with the VariableStore... did you try that?

@kkrell2016
Copy link
Author

I tried it and it works great.
I tried it this way, do you think its okey or is there a better option?

$config = VariableStore::get('config');
$db = new GenericDB(
    $config->getDriver(),
    $config->getAddress(),
    $config->getPort(),
    $config->getDatabase(),
    $config->getTables(),
    $config->getUsername(),
    $config->getPassword()
);

$pdo = $db->pdo();
stm = $pdo->prepare("SELECT oid from $tableName where ID = ?");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants