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

SQLite3Stmt: add an optional array parameter to execute() method, like in PDOStatement #9814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bohwaz
Copy link
Contributor

@bohwaz bohwaz commented Oct 24, 2022

This change adds a new array parameter to $stmt->execute() to be able to quickly pass parameters values, without having to use bindValue method.

This is to improve the usability of the SQLite3 extension API and motivate people to use parameterized values for security reasons.

For convenience, the array is treated as if it starts at index 1 instead of index zero.

Usage is the same as in PDO:

$db = new SQLite3(':memory:');
$st = $db->prepare('SELECT ?;');
$r = $st->execute(['test']);
var_dump($r->fetchArray());

BC-break: none.

@cmb69
Copy link
Contributor

cmb69 commented Oct 25, 2022

I think this makes sense, but I wonder whether there should be a way to specify the types of the binding (SQLITE3_INTEGER etc.) Maybe nested arrays? Likely more an issue for other databases which are strictly typed.

@bohwaz
Copy link
Contributor Author

bohwaz commented Oct 25, 2022

I think this makes sense, but I wonder whether there should be a way to specify the types of the binding (SQLITE3_INTEGER etc.) Maybe nested arrays? Likely more an issue for other databases which are strictly typed.

This seems quite unintuitive, it's better to use bindValue for that. Also, the SQLite3 extension is already deducing the SQLite type from the PHP type :)

So [42, null, 'string'] will be treated as INTEGER, NULL, and TEXT :)

So you can just cast a string to an int for example if you want to have it stored as INTEGER.

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

Successfully merging this pull request may close these issues.

None yet

2 participants