Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z bazą danych...
Forum PHP.pl > Forum > Bazy danych > MySQL
Amator001
Cześć wszystkim,

mam problem z podpięciem bazy danych. Strona przestała działać wskutek omyłkowo zmienionego hasła w home.pl, otrzymuję taki oto komunikat:

Kod
Błąd podczas próby nawiązania połącznia z hostem: mysql:host=localhost;dbname=11898081!
SQLSTATE[28000] [1045] Access denied for user '11898081'@'localhost' (using password: YES)
Fatal error: Call to a member function query() on a non-object in /libs/Aero/PDO/simple.php on line 89

Nie mam pojęcia, gdzie owe hasło wpisać:
  1. <?php
  2.  
  3. {
  4. private static $_instance = null;
  5.  
  6. protected $_pdo = null; // obiekt PDO, połączenie z baza danych
  7. protected $_stmt = null; // ostatnio zwrócony statement
  8.  
  9. /**
  10. * array( 'dsn' => string,
  11. * 'username' => string,
  12. * 'password' => string,
  13. * 'host' => string
  14. * 'name' => string
  15. * 'driver' => string
  16. * charset => string
  17. * );
  18. *
  19. * @var array
  20. */
  21. protected $_config = array();
  22.  
  23. public function __construct(array $config)
  24. {
  25. if (empty($config['driver'])) $config['driver'] = 'mysql';
  26. if (empty($config['host'])) $config['host'] = 'localhost';
  27. if (empty($config['charset'])) $config['charset'] = 'UTF-8';
  28. if (empty($config['username'])) $config['username'] = $config['user'];
  29. if (empty($config['password'])) $config['password'] = $config['pass'];
  30. if (empty($config['dsn'])) $config['dsn'] = $config['driver'].':host='.$config['host'].';dbname='.$config['name'];//.';charset='.$config['charset'];
  31.  
  32. $this->_config = $config;
  33. }
  34.  
  35. public function pdo() // pobiera obiekt pdo i przy okazji nawiązuje połączenie
  36. {
  37. if ($this->_pdo == null) { // nawiąż połączenie
  38. try {
  39. $this->_pdo = new PDO($this->_config['dsn'], $this->_config['username'], $this->_config['password'], array(
  40. PDO::ATTR_EMULATE_PREPARES => false,
  41. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  42. ));
  43. $this->exec("SET NAMES 'utf8'");
  44. } catch (PDOException $e) {
  45. echo 'Błąd podczas próby nawiązania połącznia z hostem: '.$this->_config['dsn'].'!<br />';
  46. echo $e->getMessage();
  47. }
  48. }
  49. return $this->_pdo;
  50. }
  51.  
  52. /*
  53. PDO::FETCH_ASSOC
  54. zwraca tablice z kluczami odzwierciedlającymi nazwy kolumn
  55. PDO::FETCH_BOTH (domyślny)
  56. zwraca tablice z kluczami jako nazwy kolumn oraz jako kolejny numer kolumny
  57. PDO::FETCH_NUM
  58. kolejne wartości zwróconego wiersza znajdują się pod kolejnymi kluczami począwszy od 0
  59. PDO::FETCH_OBJ
  60. zwraca nam wiersz jako anonimowy obiekt z własnościami o nazwach kolumn
  61.   */
  62.  
  63.  
  64. // Pobiera 1 wiersz
  65. public function fetch($sql, $mode = PDO::FETCH_ASSOC)
  66. {
  67. try {
  68. $this->_stmt = $this->pdo()->query($sql);
  69. } catch (PDOException $e) {
  70. if (DEBUG_MODE) {
  71. $errors = $this->_stmt->errorInfo();
  72. echo '<b>PDO ERROR</b><br />' ;
  73. echo ''.$sql.'<br /><br />';
  74. echo 'ERROR: '.$errors[2].'<br /><br />';
  75. echo 'TRACE: '.str_replace('#', '<br />#', $e->getTraceAsString()).'<br />';
  76. }
  77. }
  78.  
  79. return $this->_stmt->fetch($mode);
  80. }
  81.  
  82. // Pobiera wszystkie wiersze
  83. public function fetchAll($sql, $mode = PDO::FETCH_ASSOC)
  84. {
  85. try {
  86. $this->_stmt = $this->pdo()->query($sql);
  87. } catch (PDOException $e) {
  88. if (DEBUG_MODE) {
  89. $errors = $this->_stmt->errorInfo();
  90. echo '<b>PDO ERROR</b><br />' ;
  91. echo ''.$sql.'<br /><br />';
  92. echo 'ERROR: '.$errors[2].'<br /><br />';
  93. echo 'TRACE: '.str_replace('#', '<br />#', $e->getTraceAsString()).'<br />';
  94. }
  95. }
  96.  
  97. return $this->_stmt->fetchAll($mode);
  98. }
  99.  
  100. // Zlicza ilość wierszy
  101. public function rowCount($sql = null)
  102. {
  103. if ($sql == null) { // pobierz z ostatnio wykonanego zapytania
  104. return (int)$this->_stmt->rowCount();
  105. }
  106.  
  107. try {
  108. $this->_stmt = $this->pdo()->query($sql);
  109. } catch (PDOException $e) {
  110. if (DEBUG_MODE) {
  111. $errors = $this->_stmt->errorInfo();
  112. echo '<b>PDO ERROR</b><br />' ;
  113. echo ''.$sql.'<br /><br />';
  114. echo 'ERROR: '.$errors[2].'<br /><br />';
  115. echo 'TRACE: '.str_replace('#', '<br />#', $e->getTraceAsString()).'<br />';
  116. }
  117. }
  118.  
  119. return (int)$this->_stmt->rowCount();
  120. }
  121.  
  122. public function exec($sql)
  123. {
  124. try {
  125. $result = $this->pdo()->exec($sql);
  126. } catch (PDOException $e) {
  127. if (DEBUG_MODE) {
  128. $errors = $this->_stmt->errorInfo();
  129. echo '<b>PDO ERROR</b><br />' ;
  130. echo ''.$sql.'<br /><br />';
  131. echo 'ERROR: '.$errors[2].'<br /><br />';
  132. echo 'TRACE: '.str_replace('#', '<br />#', $e->getTraceAsString()).'<br />';
  133. }
  134. }
  135. return $result;
  136. }
  137.  
  138. public function lastInsertId()
  139. {
  140. return $this->pdo()->lastInsertId();
  141. }
  142.  
  143. public function beginTransaction()
  144. {
  145. $this->pdo()->beginTransaction();
  146. }
  147.  
  148. public function rollBack()
  149. {
  150. $this->pdo()->rollBack();
  151. }
  152.  
  153. public function commit()
  154. {
  155. $this->pdo()->commit();
  156. }
  157.  
  158. public static function getInstance($config = array())
  159. {
  160. if (is_null(self::$_instance)) {
  161. if (count($config) == 0 || !is_array($config)) throw new Exception('Brak konfiguracji bazy danych');
  162.  
  163. self::$_instance = new self($config);
  164. }
  165. return self::$_instance;
  166. }
  167. }
  168.  
  169. ?>

Dzięki z góry za wszelką pomoc :)
markonix
Na pewno nie w tym pliku (chociaż na sztywno byś mógł ustawić).
Poszukaj pliku o nazwie config, setup etc.
W nich powinna być tablica z indeksem password i username i reszta danych.
nospor
Gdzies tam w odmetach kodu, ktorego nie pokazales, jest ustawiona wartosc dla: $config['pass'];
Tam masz wlasnie zmienic smile.gif
Amator001
Hasło podawać w ciągu "$config['pass']"? Dołączam jeszcze kody z dwóch plików PHP.

config.php:
  1. <?php
  2.  
  3. {
  4. private static $_config = null;
  5. private $configBySegment = array();
  6. private $configByKey = array();
  7.  
  8. private $pdo = null;
  9.  
  10. public function __construct()
  11. {
  12. $this->pdo = Cube_Registry::get('pdo');
  13. $rows = $this->pdo->fetchAll('SELECT * FROM config');
  14. foreach ($rows as $r)
  15. {
  16. $this->configBySegment[$r['segment']][] = array('id' => $r['id'], 'k' => $r['k'], 'v' => $r['v']);
  17. $this->configByKey[$r['k']] = array('id' => $r['id'], 'k' => $r['k'], 'v' => $r['v'], 'segment' => $r['segment']);
  18. }
  19. }
  20.  
  21. public function __clone() {}
  22.  
  23. public static function getInstance()
  24. {
  25. if (self::$_config === null) {
  26. self::$_config = new self();
  27. }
  28. return self::$_config;
  29. }
  30.  
  31. public function get($key, $segment = null, $onlyValue = true)
  32. {
  33. if (!isset($this->configByKey[$key])) return null;
  34.  
  35. if (!is_null($segment)) {
  36. $seg = (array)$this->configBySegment[$segment];
  37. foreach ($seg as $v)
  38. {
  39. if ($v['k'] == $key) {
  40. if ($onlyValue) return $v['v'];
  41. else return $v;
  42. }
  43. }
  44. }
  45. if ($onlyValue) return $this->configByKey[$key]['v'];
  46. return $this->configByKey[$key];
  47. }
  48.  
  49. public function segment($segment)
  50. {
  51. if (!isset($this->configBySegment[$segment])) throw new Exception('Cube_Config::segment('.$segment.') - nie istnieje segment.');
  52. return $this->configBySegment[$segment];
  53. }
  54.  
  55. public function update($k, $v, $s = null)
  56. {
  57. if (!is_null($s))
  58. $s = ' AND segment = "'.$s.'"';
  59. $sql = 'UPDATE config SET v = "'.$v.'" WHERE k = "'.$k.'"'.$s;
  60. return $this->pdo->exec($sql);
  61. }
  62.  
  63. public function insert($k, $v, $s)
  64. {
  65. $this->pdo->exec('INSERT INTO config VALUES (null, "'.$k.'", "'.$v.'", "'.$s.'")');
  66. }
  67.  
  68. public function exists($k)
  69. {
  70. if (!isset($this->configByKey[$k])) return false;
  71. return true;
  72. }
  73. }
  74.  
  75. ?>


dbMysql.php:
  1. <?php
  2.  
  3. {
  4. private static $_instance = null;
  5. private $_status = false;
  6. private $_connection = null;
  7.  
  8. private function __clone() {}
  9. private function __construct($dbSettings)
  10. {
  11. $this->_status = true;
  12. $connection = mysql_connect($dbSettings['host'], $dbSettings['user'], $dbSettings['pass']) or die('nie mozna polaczyc sie z db');
  13. mysql_select_db($dbSettings['name'], $connection) or die('nie mozna wybrac bazy');
  14. $this->_connection = $connection;
  15. mysql_query("SET NAMES 'utf8'");
  16. }
  17.  
  18. public function __destruct()
  19. {
  20. $this->_status = false;
  21. $this->_connection = '';
  22. }
  23.  
  24. public function getStatus()
  25. {
  26. return $this->_status;
  27. }
  28.  
  29. public static function getInstance($dbSettings)
  30. {
  31. if (is_null(self::$_instance)) self::$_instance = new self($dbSettings);
  32. return self::$_instance;
  33. }
  34. }
  35.  
  36. ?>
markonix
Nie szukaj po klasach tylko po plikach konfiguracyjnych.
Ta pierwsza klasa config to ustawienia pobierane z bazy, logicznie rzec biorąc nie może w niej się znajdować hasło do bazy danych..
Amator001
Znalazłem plik setup-config.php, strona jest postawiona jakby na WordPressie, tyle że nie sposób się do niej dostać z poziomu wp-admin. Przez tę omyłkową zmianę hasła nie działa cały sajt :/

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title><?php _e( 'WordPress &rsaquo; Setup Configuration File' ); ?></title>
  6. <link rel="stylesheet" href="css/install.css?ver=<?php echo preg_replace( '/[^0-9a-z\.-]/i', '', $wp_version ); ?>" type="text/css" />
  7. <link rel="stylesheet" href="../wp-includes/css/buttons.css?ver=<?php echo preg_replace( '/[^0-9a-z\.-]/i', '', $wp_version ); ?>" type="text/css" />
  8.  
  9. </head>
  10. <body class="wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>">
  11. <h1 id="logo"><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>"><?php _e( 'WordPress' ); ?></a></h1>
  12. <?php
  13. } // end function setup_config_display_header();
  14.  
  15. switch($step) {
  16. case 0:
  17. setup_config_display_header();
  18. ?>
  19.  
  20. <p><?php _e( 'Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.' ) ?></p>
  21. <ol>
  22. <li><?php _e( 'Database name' ); ?></li>
  23. <li><?php _e( 'Database username' ); ?></li>
  24. <li><?php _e( 'Database password' ); ?></li>
  25. <li><?php _e( 'Database host' ); ?></li>
  26. <li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
  27. </ol>
  28. <p><strong><?php _e( "If for any reason this automatic file creation doesn’t work, don’t worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>." ); ?></strong></p>
  29. <p><?php _e( "In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you’re all ready&hellip;" ); ?></p>
  30.  
  31. <p class="step"><a href="setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&amp;noapi'; ?>" class="button button-large"><?php _e( 'Let’s go!' ); ?></a></p>
  32. <?php
  33. break;
  34.  
  35. case 1:
  36. setup_config_display_header();
  37. ?>
  38. <form method="post" action="setup-config.php?step=2">
  39. <p><?php _e( "Below you should enter your database connection details. If you’re not sure about these, contact your host." ); ?></p>
  40. <table class="form-table">
  41. <tr>
  42. <th scope="row"><label for="dbname"><?php _e( 'Database Name' ); ?></label></th>
  43. <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
  44. <td><?php _e( 'The name of the database you want to run WP in.' ); ?></td>
  45. </tr>
  46. <tr>
  47. <th scope="row"><label for="uname"><?php _e( 'User Name' ); ?></label></th>
  48. <td><input name="uname" id="uname" type="text" size="25" value="<?php echo htmlspecialchars( _x( 'username', 'example username' ), ENT_QUOTES ); ?>" /></td>
  49. <td><?php _e( 'Your MySQL username' ); ?></td>
  50. </tr>
  51. <tr>
  52. <th scope="row"><label for="pwd"><?php _e( 'Password' ); ?></label></th>
  53. <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" /></td>
  54. <td><?php _e( '&hellip;and your MySQL password.' ); ?></td>
  55. </tr>
  56. <tr>
  57. <th scope="row"><label for="dbhost"><?php _e( 'Database Host' ); ?></label></th>
  58. <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
  59. <td><?php _e( 'You should be able to get this info from your web host, if <code>localhost</code> does not work.' ); ?></td>
  60. </tr>
  61. <tr>
  62. <th scope="row"><label for="prefix"><?php _e( 'Table Prefix' ); ?></label></th>
  63. <td><input name="prefix" id="prefix" type="text" value="wp_" size="25" /></td>
  64. <td><?php _e( 'If you want to run multiple WordPress installations in a single database, change this.' ); ?></td>
  65. </tr>
  66. </table>
  67. <?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="1" /><?php } ?>
  68. <p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
  69. </form>
  70. <?php
  71. break;
  72.  
  73. case 2:
  74. foreach ( array( 'dbname', 'uname', 'pwd', 'dbhost', 'prefix' ) as $key )
  75. $$key = trim( wp_unslash( $_POST[ $key ] ) );
  76.  
  77. $tryagain_link = '</p><p class="step"><a href="setup-config.php?step=1" onclick="java script:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>';
  78.  
  79. if ( empty( $prefix ) )
  80. wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' . $tryagain_link ) );
  81.  
  82. // Validate $prefix: it can only contain letters, numbers and underscores.
  83. if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
  84. wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' . $tryagain_link ) );
  85.  
  86. // Test the db connection.
  87. /**#@+
  88. * @ignore
  89. */
  90. define('DB_NAME', $dbname);
  91. define('DB_USER', $uname);
  92. define('DB_PASSWORD', $pwd);
  93. define('DB_HOST', $dbhost);
  94. /**#@-*/
  95.  
  96. // We'll fail here if the values are no good.
  97. require_wp_db();
  98. if ( ! empty( $wpdb->error ) )
  99. wp_die( $wpdb->error->get_error_message() . $tryagain_link );
  100.  
  101. // Fetch or generate keys and salts.
  102. $no_api = isset( $_POST['noapi'] );
  103. if ( ! $no_api ) {
  104. require_once( ABSPATH . WPINC . '/class-http.php' );
  105. require_once( ABSPATH . WPINC . '/http.php' );
  106. wp_fix_server_vars();
  107. /**#@+
  108. * @ignore
  109. */
  110. function get_bloginfo() {
  111. return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) );
  112. }
  113. /**#@-*/
  114. $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
  115. }
  116.  
  117. if ( $no_api || is_wp_error( $secret_keys ) ) {
  118. $secret_keys = array();
  119. require_once( ABSPATH . WPINC . '/pluggable.php' );
  120. for ( $i = 0; $i < 8; $i++ ) {
  121. $secret_keys[] = wp_generate_password( 64, true, true );
  122. }
  123. } else {
  124. $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) );
  125. foreach ( $secret_keys as $k => $v ) {
  126. $secret_keys[$k] = substr( $v, 28, 64 );
  127. }
  128. }
  129.  
  130. $key = 0;
  131. // Not a PHP5-style by-reference foreach, as this file must be parseable by PHP4.
  132. foreach ( $config_file as $line_num => $line ) {
  133. if ( '$table_prefix =' == substr( $line, 0, 16 ) ) {
  134. $config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
  135. continue;
  136. }
  137.  
  138. if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) )
  139. continue;
  140.  
  141. $constant = $match[1];
  142. $padding = $match[2];
  143.  
  144. switch ( $constant ) {
  145. case 'DB_NAME' :
  146. case 'DB_USER' :
  147. case 'DB_PASSWORD' :
  148. case 'DB_HOST' :
  149. $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n";
  150. break;
  151. case 'AUTH_KEY' :
  152. case 'SECURE_AUTH_KEY' :
  153. case 'LOGGED_IN_KEY' :
  154. case 'NONCE_KEY' :
  155. case 'AUTH_SALT' :
  156. case 'SECURE_AUTH_SALT' :
  157. case 'LOGGED_IN_SALT' :
  158. case 'NONCE_SALT' :
  159. $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n";
  160. break;
  161. }
  162. }
  163. unset( $line );
  164.  
  165. if ( ! is_writable(ABSPATH) ) :
  166. setup_config_display_header();
  167. ?>
  168. <p><?php _e( "Sorry, but I can’t write the <code>wp-config.php</code> file." ); ?></p>
  169. <p><?php _e( 'You can create the <code>wp-config.php</code> manually and paste the following text into it.' ); ?></p>
  170. <textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php
  171. foreach( $config_file as $line ) {
  172. echo htmlentities($line, ENT_COMPAT, 'UTF-8');
  173. }
  174. ?></textarea>
  175. <p><?php _e( 'After you’ve done that, click “Run the install.”' ); ?></p>
  176. <p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
  177. <script>
  178. (function(){
  179. var el=document.getElementById('wp-config');
  180. el.focus();
  181. el.select();
  182. })();
  183. </script>
  184. <?php
  185. else :
  186. $handle = fopen(ABSPATH . 'wp-config.php', 'w');
  187. foreach( $config_file as $line ) {
  188. fwrite($handle, $line);
  189. }
  190. fclose($handle);
  191. chmod(ABSPATH . 'wp-config.php', 0666);
  192. setup_config_display_header();
  193. ?>
  194. <p><?php _e( "All right, sparky! You’ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;" ); ?></p>
  195.  
  196. <p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
  197. <?php
  198. endif;
  199. break;
  200. }
  201. ?>
  202. </body>
  203. </html>
Pyton_000
Wejdź człowieku w index.php i szukaj po nitce... Przeglądaj od góry includowane pliki aż dojdziesz gdzieś do jakiegoś configdupaplikjakistam.php
Amator001
Cytat(Pyton_000 @ 27.05.2015, 13:34:49 ) *
Wejdź człowieku w index.php i szukaj po nitce... Przeglądaj od góry includowane pliki aż dojdziesz gdzieś do jakiegoś configdupaplikjakistam.php

Już sobie poradziłem, dzięki wszystkim za pomoc :)
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.