Guest User

Untitled

a guest
Jan 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. update tbl set field1 = isnull(?, field1), field2 = isnull(?, field2) where id = ?
  2.  
  3. use DoctrineDBALDriverManager;
  4.  
  5. include_once __DIR__ . '/vendor/autoload.php';
  6.  
  7. $connectionOptions = array_merge(
  8. ['driverClass' => 'DoctrineDBALDriverPDOSqlsrvDriver'],
  9. ['host' => '127.0.0.1', 'port' => 1433, 'dbname' => 'users', 'user' => '', 'password' => '']
  10. );
  11.  
  12. try {
  13. $conn = DriverManager::getConnection($connectionOptions);
  14. } catch (Exception $e) {
  15. die($e->getMessage());
  16. }
  17.  
  18. $userId = 1;
  19. $nick = 'test';
  20.  
  21. try {
  22. $result = $conn->executeUpdate(
  23. 'UPDATE users.users SET user_nick = isnull(:nick, user_nick) WHERE user_id = :userId',
  24. ['nick' => $nick, 'userId' => $userId],
  25. ['nick' => PDO::NULL_EMPTY_STRING, 'userId' => PDO::PARAM_INT]
  26. );
  27. } catch (Exception $e) {
  28. die($e->getMessage());
  29. }
Add Comment
Please, Sign In to add comment