Connect database site php5 to php7 [duplicated]

0

I'm trying to move my site to a server with php7 with mysqli:

I have a conexion.php file that I modified and now looks like this:

<?php

$hostname_conexion = "localhost";
$database_conexion = "opentach";
$username_conexion = "root";
$password_conexion = "";

# $conexion = mysql_connect($hostname_conexion, $username_conexion, $password_conexion) or trigger_error(mysql_error(),E_USER_ERROR); 

$conexion = new mysqli('localhost', 'root', '', 'opentach');


?>

I have only commented the mysql_connect line and I have incorporated the mysqli line

When loading it gives me the following error, which means?:

  

Warning: mysqli_select_db () expects parameter 1 to be mysqli, string   given in /var/www/html/opentach/index.php on line 84

     

Warning: mysqli_query () expects parameter 1 to be mysqli, string given   in /var/www/html/opentach/index.php on line 86

     

Warning: mysqli_error () expects exactly 1 parameter, 0 given in   /var/www/html/opentach/index.php on line 86

the lines of the index they refer to are:

mysqli_select_db($database_conexion, $conexion);
$query_datos_meta = "SELECT * FROM configuracion WHERE idioma = '".$_SESSION['idioma']."'";
$datos_meta = mysqli_query($query_datos_meta, $conexion) or die(mysqli_error());
$row_datos_meta = mysqli_fetch_assoc($datos_meta);
$totalRows_datos_meta = mysqli_num_rows($datos_meta);

It's modified, the only thing I've done is change mysql by mysqli .

    
asked by Guzmán González 12.01.2018 в 12:50
source

1 answer

0

I have the connections as follows from PHP5 to PHP7. Try to modify as little as possible because you had many queries to modify.

Connection

$link = mysqli_connect('servidor', 'mi_usuario', 'mi_contraseña', 'mi_bd');

Query

$query = 'SELECT * FROM Opciones';

See

$result = $link->query($query);

Print

while ($line = mysqli_fetch_assoc($result)) {
    echo "<tr><td>".$line["id"]."</td></tr>";
}
    
answered by 12.01.2018 в 13:07