I can't connect to the database from my website, everything is configured correctly in the main

Website URL

http://www.distflores.rf.gd/

Error Message

Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘if0_38432103 ‘@‘192.168.0.67’ (using password: YES) in /home/vol3_4/infinityfree.com/if0_38432103/htdocs/php/main.php:5 Stack trace: #0 /home/vol3_4/infinityfree.com/if0_38432103/htdocs/php/main.php(5): PDO->__construct(‘mysql:host=sql2…’, ‘if0_38432103 ‘, Object(SensitiveParameterValue)) #1 /home/vol3_4/infinityfree.com/if0_38432103/htdocs/php/iniciar_sesion.php(41): conexion() #2 /home/vol3_4/infinityfree.com/if0_38432103/htdocs/vistas/login.php(27): require_once(’/home/vol3_4/in…’) #3 /home/vol3_4/infinityfree.com/if0_38432103/htdocs/index.php(31): include(’/home/vol3_4/in…’) #4 {main} thrown in /home/vol3_4/infinityfree.com/if0_38432103/htdocs/php/main.php on line 5

Other Information

(other information and details relevant to your question)

You have the wrong password, or the wrong database name. Your DB password is different from the one you use to logging to the client area. Check the database section to get the correct password, reset your hosting account password (NOT your client area password) if you have the correct value copied.

Also make sure the database name is typed correctly and exists in the control panel, it should look like if0_38432103_xxxxxx

9 Likes

Yes, in fact I used the copy buttons provided in the connection section, but I still get the same error.

Looking at this, this is definaitly looks like an incorrect credentials issue. To be sure, can you share the PHP you’re using, but with your password removed, so we can look tosee if there are any errors?

4 Likes

Yeah, is this:

<?php
	
	# Conexion a la base de datos #
	function conexion(){
		$pdo = new PDO('mysql:host=sql201.infinityfree.com;dbname=if0_38432103_inventarios', 'if0_38432103 ', '');
		return $pdo;
	}


	# Verificar datos #
	function verificar_datos($filtro,$cadena){
		if(preg_match("/^".$filtro."$/", $cadena)){
			return false;
        }else{
            return true;
        }
	}


	# Limpiar cadenas de texto #
	function limpiar_cadena($cadena){
		$cadena=trim($cadena);
		$cadena=stripslashes($cadena);
		$cadena=str_ireplace("<script>", "", $cadena);
		$cadena=str_ireplace("</script>", "", $cadena);
		$cadena=str_ireplace("<script src", "", $cadena);
		$cadena=str_ireplace("<script type=", "", $cadena);
		$cadena=str_ireplace("SELECT * FROM", "", $cadena);
		$cadena=str_ireplace("DELETE FROM", "", $cadena);
		$cadena=str_ireplace("INSERT INTO", "", $cadena);
		$cadena=str_ireplace("DROP TABLE", "", $cadena);
		$cadena=str_ireplace("DROP DATABASE", "", $cadena);
		$cadena=str_ireplace("TRUNCATE TABLE", "", $cadena);
		$cadena=str_ireplace("SHOW TABLES;", "", $cadena);
		$cadena=str_ireplace("SHOW DATABASES;", "", $cadena);
		$cadena=str_ireplace("<?php", "", $cadena);
		$cadena=str_ireplace("?>", "", $cadena);
		$cadena=str_ireplace("--", "", $cadena);
		$cadena=str_ireplace("^", "", $cadena);
		$cadena=str_ireplace("<", "", $cadena);
		$cadena=str_ireplace("[", "", $cadena);
		$cadena=str_ireplace("]", "", $cadena);
		$cadena=str_ireplace("==", "", $cadena);
		$cadena=str_ireplace(";", "", $cadena);
		$cadena=str_ireplace("::", "", $cadena);
		$cadena=trim($cadena);
		$cadena=stripslashes($cadena);
		return $cadena;
	}


	# Funcion renombrar fotos #
	function renombrar_fotos($nombre){
		$nombre=str_ireplace(" ", "_", $nombre);
		$nombre=str_ireplace("/", "_", $nombre);
		$nombre=str_ireplace("#", "_", $nombre);
		$nombre=str_ireplace("-", "_", $nombre);
		$nombre=str_ireplace("$", "_", $nombre);
		$nombre=str_ireplace(".", "_", $nombre);
		$nombre=str_ireplace(",", "_", $nombre);
		$nombre=$nombre."_".rand(0,100);
		return $nombre;
	}


	# Funcion paginador de tablas #
	function paginador_tablas($pagina,$Npaginas,$url,$botones){
		$tabla='<nav class="pagination is-centered is-rounded" role="navigation" aria-label="pagination">';

		if($pagina<=1){
			$tabla.='
			<a class="pagination-previous is-disabled" disabled >Anterior</a>
			<ul class="pagination-list">';
		}else{
			$tabla.='
			<a class="pagination-previous" href="'.$url.($pagina-1).'" >Anterior</a>
			<ul class="pagination-list">
				<li><a class="pagination-link" href="'.$url.'1">1</a></li>
				<li><span class="pagination-ellipsis">&hellip;</span></li>
			';
		}

		$ci=0;
		for($i=$pagina; $i<=$Npaginas; $i++){
			if($ci>=$botones){
				break;
			}
			if($pagina==$i){
				$tabla.='<li><a class="pagination-link is-current" href="'.$url.$i.'">'.$i.'</a></li>';
			}else{
				$tabla.='<li><a class="pagination-link" href="'.$url.$i.'">'.$i.'</a></li>';
			}
			$ci++;
		}

		if($pagina==$Npaginas){
			$tabla.='
			</ul>
			<a class="pagination-next is-disabled" disabled >Siguiente</a>
			';
		}else{
			$tabla.='
				<li><span class="pagination-ellipsis">&hellip;</span></li>
				<li><a class="pagination-link" href="'.$url.$Npaginas.'">'.$Npaginas.'</a></li>
			</ul>
			<a class="pagination-next" href="'.$url.($pagina+1).'" >Siguiente</a>
			';
		}

		$tabla.='</nav>';
		return $tabla;
	}
1 Like

Comparing to my code I can see one main diference “sql210.infinityfree.com”, but yours is showing as “sql201.infinityfree.com” This might be causing the error your seeing?

Here’s my code for you to compare

$servername = "sql210.infinityfree.com";
$username = "if0_37954203";
$password = " ";
$dbname = "if0_37954203_cv_data";

try {
    // Create connection using PDO and set charset to utf8mb4
    $conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4", $username, $password);
    // Set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Query to fetch all records from the Employment table sorted by StartDate in descending order
    $sql = "SELECT * FROM Employment ORDER BY StartDate DESC";
    $stmt = $conn->prepare($sql);
    $stmt->execute();

    // Set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $rows = $stmt->fetchAll();
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

Is this inside a function? Is if it is, be very careful about defining functions inside other functions. If it is not, you are using return very incorrectly.

This is the issue, you have a whitespace character at the end of the username

Doubtfully, there are a lot of different MySQL subdmains that are used, the OP is probably on 201 where you are on 210

7 Likes

fair enough, that was the only diference I could see. The only other person who’s code I’ve seen is my dad’s who happens to be on 210 too, so I assuemed that was the normal haha.

well spotted.

6 Likes

Thank you very much, it was a silly mistake (the space) :rofl:, but I managed to correct it. Thanks @Greenreader9 :folded_hands:

4 Likes

No problem :slight_smile:

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.