Problem with connect to database (CODE IGNITER)

Hey. I have a page hosted on a subdomain at 000webhost free. This is a page made in model view controller with Codeigniter, and I have problems when connecting to the database. I can not make any kind of consultation, whether for logging users display a table of books etc. … I would like to know if anyone knows any reason. I can put somewhere in the code and error.
Use active record to query and connect

Normally this type of problems (problem with connection to the database) are resolved when the user enters the 4 data needed to make the connection in the right place.

Note that the name of the database server is not localhost. It is mysqlXX.000webhost.com type.

The parameters of the database.php file you mean? They are correct.
It is another problem, because I load the page it does not do well is access to the database does not return anything if I make a select for logging a user, for example

Do you get any error messages?
Can you tell us exactly which page the error occurs?

This is the website to identify with alberto alberto, I get this error.

Fatal error: Call to a member function row_array () on a non-object in / home/a1588400/public_html/application/models/usuarios.php on line 20

The error is in this part of code:

  function identify ($ usu, $ clear)

{

$ sql = ‘select * from’. $ this-> table. “where username = ‘$ USER’ and password = ‘$ cla’”;

$ salt = $ this-> db-> query ($ sql);

$ res = $ salt-> row_array ();

return $ res;

}

Thank you very much

Hello,

It seems that the connection to the database is done correctly, because it does not show a mysql error.

You can check the following:

  1. Checks in the table of the database data exist.

  2. On the line where you call the function / method checks that the object was created correctly.

Sorry I had not activated the db_debug
the error is this

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core / Loader.php

Line Number: 346

Unable to connect to your database server using the provided settings.

Filename: /home/a1588400/public_html/models/usuarios.php

Line Number: 19

function identificar($usu,$cla)
{
$val = false;
$res = $this->db->from($this->tabla)
->where(‘usuario’,$usu)
->where(‘clave’,$cla)
->get();--------------------------------------------------line 19

$val = $res->num_rows() == 1?$res->row_array():false;

$res->free_result();

return $val;
}

I think that you have entered some incorrect information in connection to your database. You can try to write the connection data in the following file, and upload and execute on the server to verify that the data you’re using are correct:


<?php	
// Localhost
	if (!defined('SQL_HOST')) define('SQL_HOST', 'YOUR_SERVER');
	if (!defined('SQL_DB')) define('SQL_DB','YOUR_DATABASE');  
	if (!defined('USER')) define('USER', 'YOUR_DATABASE_USER');
	if (!defined('PASS')) define('PASS','YOUR_PASSWORD');
	$bd=mysql_connect(SQL_HOST, USER, PASS);  // utilizar cuando el servidor es localhost
	if (!$bd) 
		{
			echo ("Error conectando con el SERVIDOR: ".mysql_error());
			exit();
		}
	$sel=@mysql_select_db(SQL_DB);
		if (!$sel)
		{
			echo ("Error cargando la BASE DE DATOS: ".mysql_error());
			exit();
		}
                echo '<p>La conexión a la base de datos se ha realizado de forma correcta</p>';
?>

one moment

one moment

I have this error…

A PHP Error was encountered

Severity: Warning

Message: mysql_connect() [function.mysql-connect]: Host ‘srv41.000webhost.com’ is not allowed to connect to this MySQL server

Filename: models/usuarios.php

Line Number: 22
Error conectando con el SERVIDOR: Host ‘srv41.000webhost.com’ is not allowed to connect to this MySQL server


function identificar($usu,$cla)
    {
        $val = false;

    if (!defined('SQL_HOST')) define('SQL_HOST', 'YOUR_SERVER');
    if (!defined('SQL_DB')) define('SQL_DB','YOUR_DATABASE');  
    if (!defined('USER')) define('USER', 'YOUR_DATABASE_USER');
    if (!defined('PASS')) define('PASS','YOUR_PASSWORD');
    
    $bd=mysql_connect(SQL_HOST, USER, PASS);  // utilizar cuando el servidor es localhost-----------------------line 22
    if (!$bd) 
        {
            echo ("Error conectando con el SERVIDOR: ".mysql_error());
            exit();
        }
    $sel=@mysql_select_db(SQL_DB);
        if (!$sel)
        {
            echo ("Error cargando la BASE DE DATOS: ".mysql_error());
            exit();
        }


        return $val;
    }

Hi,
Your problem is that you misspelled the name of the server database.

Note that servers databases have names like mysqlXX.000webhost.com where XX is a number.
To see what your database server goes into CPanel -> MySQL.

[spanish version]
Tu problema es que has escrito mal el nombre del servidor de la base de datos.

Date cuenta de que los servidores de las bases de datos tienen nombres como mysqlXX.000webhost.com donde XX es un número.

Para ver cual es tu servidor de base de datos entra en CPanel -> MySQL.

Hey, I have a problem with the database connection like this
Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 346
my database config has match with the host, db, and user
can anyone help? sory for my bad english

Are you trying to remotely use MYSQL?

Unable to connect to your database server using the provided settings.

Hi Jona, just an FYI, remote connections on FTP are not allowed on free accounts by the way.

No encuentro el nombre del servidor de base de datos!..podrías ayudarme?

@dudacris94 Puede encontrar todos los detalles de la base de datos en “Administrar base de datos”