Advertisement
Trigub_Ilia

Подключение к базе по MSSQL

Jan 10th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. /*
  2. /usr/local/etc/odbc.ini
  3. --
  4. [MSSQLServer]
  5. Driver = SQL Server Native Client 11.0
  6. Description = Sample Database
  7. Trace = Yes
  8. Server =
  9. Port = 1433
  10. Database =
  11. */
  12.  
  13. /* Connect using Windows Authentication. */
  14. $conn = odbc_connect("MSSQLServer", $connectionOptions["UID"], $connectionOptions["PWD"]);
  15. if(!$conn){
  16.     echo "Sorry, not available MSSQL server.";
  17.     exit();
  18. }
  19. else{
  20.  
  21.     // удалить старые данные
  22.     $sql = "DELETE FROM ".COption::GetOptionString('studiobit.alliance', 'table_omni')." WHERE SystemAlias LIKE '%CRM%'";
  23.     if(!odbc_exec($conn, $sql)){
  24.         p2f($sql.": Query failed " .odbc_error());
  25.     }
  26.  
  27.     // добавлить новые данные
  28.     foreach($result as $key=>$arItem){
  29.         $sql = "INSERT INTO ".COption::GetOptionString('studiobit.alliance', 'table_omni')." (".implode(', ', $keyTable).") values (".str_replace('"', "'", "\"".implode('", "', $arItem)."\"").")";
  30.  
  31.         $res = odbc_exec($conn, $sql);
  32.  
  33.         if (!$res){
  34.             p2f($sql." | Query failed " .odbc_error());
  35.         }else {
  36.             $i++;
  37.         }
  38.  
  39.     }
  40. }
  41.  
  42. odbc_close($conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement