Changeset 5236 for trunk/include


Ignore:
Timestamp:
Mar 21, 2010, 11:51:36 PM (14 years ago)
Author:
nikrou
Message:

Feature 1255 :
only one function
use exceptions to deal with differents possible errors

Location:
trunk/include
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r5235 r5236  
    105105
    106106// Database connection
    107 $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
    108                               $conf['db_password'], $conf['db_base']);
    109 pwg_select_db($conf['db_base'], $pwg_db_link);
     107try
     108{
     109  $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
     110                                $conf['db_password'], $conf['db_base']);
     111}
     112catch (Exception $e)
     113{
     114  my_error(l10n($e->getMessage(), true);
     115}
    110116
    111117pwg_db_check_charset();
  • trunk/include/dblayer/functions_mysql.inc.php

    r5230 r5236  
    3333 */
    3434
    35 function pwg_db_connect($host, $user, $password, $database=null, $die=true)
     35function pwg_db_connect($host, $user, $password, $database)
    3636
    37   $link = @mysql_connect($host, $user, $password) or my_error('mysql_connect', $die);
    38 
    39   return $link;
    40 }
    41 
    42 function pwg_select_db($database, $link, $die=true)
    43 {
    44   return @mysql_select_db($database, $link) or my_error('mysql_select_db', $die);
     37  $link = @mysql_connect($host, $user, $password);
     38  if (!$link)
     39  {
     40    throw new Exception("Can't connect to server");
     41  }
     42  if (mysql_select_db($database, $link))
     43  {
     44    return $link;
     45  }
     46  else
     47  {
     48    throw new Exception('Connection to server succeed, but it was impossible to connect to database');
     49  }
    4550}
    4651
  • trunk/include/dblayer/functions_pdo-sqlite.inc.php

    r5230 r5236  
    3434 */
    3535
    36 function pwg_db_connect($host, $user, $password, $database, $die=true)
     36function pwg_db_connect($host, $user, $password, $database)
    3737{
    3838  global $conf;
     
    4040  $db_file = sprintf('sqlite:%s/%s.db', $conf['local_data_dir'], $database);
    4141
    42   try {
    43     $link = new PDO($db_file);
    44   } catch (Exception $e) {
    45     my_error('sqlite::open', $die);
     42  $link = new PDO($db_file);
     43  if (!$link)
     44  {
     45    throw new  Exception('Connection to server succeed, but it was impossible to connect to database');
    4646  }
    4747
     
    5555
    5656  return $link;
    57 }
    58 
    59 function pwg_select_db($database=null, $link=null, $die=null)
    60 {
    61   return true;
    6257}
    6358
  • trunk/include/dblayer/functions_pgsql.inc.php

    r5230 r5236  
    3434 */
    3535
    36 function pwg_db_connect($host, $user, $password, $database, $die=true)
     36function pwg_db_connect($host, $user, $password, $database)
    3737{
    3838  $connection_string = '';
     
    5050                                $password,
    5151                                $database);
    52   $link = pg_connect($connection_string) or my_error('pg_connect', $die); 
    53 
    54   return $link;
     52  $link = pg_connect($connection_string);
     53  if (!$link)
     54  {
     55    throw new Exception("Can't connect to server");
     56  }
     57  else
     58  {
     59    return $link;
     60  }
    5561}
    5662
  • trunk/include/dblayer/functions_sqlite.inc.php

    r5230 r5236  
    3434 */
    3535
    36 function pwg_db_connect($host, $user, $password, $database, $die=true)
     36function pwg_db_connect($host, $user, $password, $database)
    3737{
    3838  global $conf;
     
    4848    $sqlite_open_mode = SQLITE3_OPEN_READWRITE;
    4949  }
    50   try {
    51     $link = new SQLite3($db_file, $sqlite_open_mode);
    52   } catch (Exception $e) {
    53     my_error('sqlite::open', $die);
     50 
     51  $link = new SQLite3($db_file, $sqlite_open_mode);
     52  if (!$link)
     53  {
     54    throw new  Exception('Connection to server succeed, but it was impossible to connect to database');
    5455  }
    5556
     
    6364
    6465  return $link;
    65 }
    66 
    67 function pwg_select_db($database=null, $link=null, $die=null)
    68 {
    69   return true;
    7066}
    7167
Note: See TracChangeset for help on using the changeset viewer.