droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 1 | <?php |
droy | 2a1f555 | 2014-11-03 11:04:38 -0500 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * Copyright (c) 2007-2014 Eclipse Foundation, Intalio, Inc., IBM Corporation and others. |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Denis Roy, Eclipse Foundation - Initial Implementation |
| 11 | * Antoine Toulme, Intalio - Backend functions |
| 12 | *******************************************************************************/ |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 13 | |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 14 | require_once(dirname(__FILE__) . "/backend_functions.php"); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 15 | class DBConnection { |
| 16 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 17 | function connect() |
| 18 | { |
| 19 | static $dbh; |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 20 | global $addon; |
| 21 | $db_params = $addon->callHook('db_params'); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 22 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 23 | $dbh = mysqli_connect($db_params['db_read_host'],$db_params['db_read_user'],$db_params['db_read_pass'],$db_params['db_read_name']); |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 24 | if (!$dbh) { |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 25 | errorLog("Failed attempt to connect to server - aborting."); |
| 26 | exitTo("/error.php?errNo=101301","error: 101301 - data server can not be found"); |
| 27 | } |
| 28 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 29 | /* |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 30 | $database = $db_params['db_read_name']; |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 31 | if (isset($database)) { |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 32 | if (!mysqli_select_db($dbh, $database)) { |
kitlo | a59efea | 2018-05-11 12:40:40 -0400 | [diff] [blame] | 33 | errorLog("Failed attempt to open database: $database - aborting \n\t" . mysqli_error($dbh)); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 34 | exitTo("/error.php?errNo=101303","error: 101303 - unknown database name"); |
| 35 | } |
droy | 2a1f555 | 2014-11-03 11:04:38 -0500 | [diff] [blame] | 36 | } |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 37 | */ |
| 38 | # mysqli_query($dbh, "SET character_set_results=latin1"); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 39 | return $dbh; |
| 40 | } |
droy | 2a1f555 | 2014-11-03 11:04:38 -0500 | [diff] [blame] | 41 | |
kitlo | a59efea | 2018-05-11 12:40:40 -0400 | [diff] [blame] | 42 | function disconnect($dbh) { |
| 43 | return mysqli_close($dbh); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | ?> |