How can I connect to a web database from my PC?

2

Well this case had not been presented to me until now, it turns out that I have an acquaintance who bought a domain (from him) and separated me a space (so to speak) on his server. I have my web hosted, I'm just going to start developing what's being the entries (it's already in the database).

The problem is that I do not know how to connect to that server. I'm not very experienced in web development as you may notice.

With what program or how can I connect to this server with this data? I have: IP address of the server, user, password.

I thought about installing wampserver and phpmyadmin, but I see that it only serves as a local (unless that is the solution and its configuration changes ...)

    
asked by TwoDent 22.09.2016 в 17:28
source

3 answers

1

Remote connections depend on the generosity of both parties when working, I explain. On the server side where the BD you need to access is, it should allow remote connections, so you usually have to configure it to allow the computer IP from which you want to access. Well, now on your side, or on the remote client, what you need is access through a handler. I show you an image with Query Browser:


Having the data that you say you have, you can access without problems. Greetings.

    
answered by 22.09.2016 / 17:47
source
1

You can connect to PHP to both local and external databases without problems, only indicating the IP address of the database (and in some cases the port). The real problem you are going to face is to tell the database to accept connections from remote users (usually the shared server databases restrict access to only local users).

As you mention, you can use a program like WAMP to have a local server (Apache + PHP) and from there run the PHP code which will connect to the remote database. If you choose this option, you will probably have to send a ticket to the server support (if the server offers support for these cases) asking that they enable the connection of remote users to the database (they will probably ask for your IP for only unblock the connection from your IP and not for remote users in general).

The other option (and more recommendable) is to work directly on the remote server. That is, upload the PHP files on that server and perform the programming there. This gives the advantage that you will be connecting to the database as a local user (since the PHP script that you upload will be on the same remote server as the database).

You can see a small article that talks about how to connect to a database to get information:

link

    
answered by 22.09.2016 в 17:34
1

I share a class to make the connection to the database, this connection is made through :

<?php

  # Clase conexion base de datos Mysqli
  # Bases de datos Mysql en php
  # PHP 5.0



class MySQL
{
  $conexion;
  $host     = "ipDelHost";
  $user     = "Usuario";
  $password = "Contrasena"
  $dbname = "NombreBaseDeDatos";

  function MySQL()
  {

  if(!isset($this->conexion))
    {
        $this->conexion = mysqli_connect($this->host,$this->user,$this->password);
      if (!$this->conexion) {
        die('error en la conexion: ' . $mysqli->connect_errno);
        exit();
      }

         mysqli_select_db($this->conexion,$this->dbname) or die("error en la conexion de base de datos: ".mysql_error());
    }
  }
/* retornará un objeto (mysqli_result) con el resultado de la consulta */
 function consultar($query)
 {
    mysqli_query("SET NAMES 'utf8'"); 
    $resultado = mysqli_query($query,$this->conexion);
    if(!$resultado)
    {
            echo 'MySQL Error: ' . mysql_error();
        exit();
    }
  return $resultado; 
  }
/* retornará "true" si el registro es exitoso */
  function registro($query)
  {
      $resultado = mysqli_query($query,$this->conexion);
    if(!$resultado)
    {
            echo 'MySQL Error: ' . mysqli_query();
        exit;
    }
    return $resultado; 
  }

 /* retornará un array con los datos de la consulta*/
 function fetch_array($query)
 { 
    return mysqli_fetch_array($query);
 }

/* Retorna el número de filas del resultado. */
 function num_rows($query)
 { 
     return mysqli_num_rows($query);
 }

 /* Retorna un array de cadenas que se corresponde con la fila obtenida (como una matrix) $fila[0], $fila[1]*/
 function fetch_row($query)
 { 
     return mysql_fetch_row($query);
 }

 /* Devuelve un array asociativo de strings que representa a la fila obtenida del conjunto de resultados, donde cada clave 
    del array representa el nombre de una de las columnas de éste; o NULL si no hubieran más filas en dicho conjunto de resultados.

    Si dos o más columnas del resultado tienen el mismo nombre de campo, la última columna tomará precedencia. Para acceder a la/s otra/s 
    columna/s con el mismo nombre, es necesario acceder al resultado ya sea usando los índices numéricos mediante mysqli_fetch_row(), 
    ya sea añadiéndole alias a los campos.

    Ejemplo

    $consulta = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";

    # obtener array asociativo 

    while ($row = mysqli_fetch_assoc($resultado)) {
        printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
    }
  */
 function fetch_assoc($consulta)
 { 
     return mysql_fetch_assoc($consulta);
 } 

}

to use it create the object of the class and call the function you need by sending the query, there tells you that returns each function, I leave an example:

<?php
/* llamas la pagina donde esta la clase de conexión */
require_once 'MySQL.php';

/* creas el objeto de la clase */
$mysql = new MySQL();
/* realizas la conexión */
$mysql->MySQL();

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
/* realizas la consulta */
$mysql->consultar($query)

I hope you serve

    
answered by 22.09.2016 в 18:03