Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update tbl set field1 = isnull(?, field1), field2 = isnull(?, field2) where id = ?
- use DoctrineDBALDriverManager;
- include_once __DIR__ . '/vendor/autoload.php';
- $connectionOptions = array_merge(
- ['driverClass' => 'DoctrineDBALDriverPDOSqlsrvDriver'],
- ['host' => '127.0.0.1', 'port' => 1433, 'dbname' => 'users', 'user' => '', 'password' => '']
- );
- try {
- $conn = DriverManager::getConnection($connectionOptions);
- } catch (Exception $e) {
- die($e->getMessage());
- }
- $userId = 1;
- $nick = 'test';
- try {
- $result = $conn->executeUpdate(
- 'UPDATE users.users SET user_nick = isnull(:nick, user_nick) WHERE user_id = :userId',
- ['nick' => $nick, 'userId' => $userId],
- ['nick' => PDO::NULL_EMPTY_STRING, 'userId' => PDO::PARAM_INT]
- );
- } catch (Exception $e) {
- die($e->getMessage());
- }
Add Comment
Please, Sign In to add comment