fatal error call to a member function prepare () on boolean in functions.php online 32

1

I am making a news system that is perfect in apache and in an online server. This error arises when running the site on a local server windows iis can be the php versions? has the 5.6

$bd_config = array(

        'basedatos' => 'noticias',
        'usuario' => 'root',
        'pass' => '****'

         );


$noticias_config = array(

        'post_por_pagina' => '3',
        'carpeta_imagenes' => 'img/'

         );

LINE 32 -------------------------------------- function.php

function obtener_post($post_por_pagina, $conexion) {

    $inicio = (pagina_actual() > 1) ? pagina_actual() * $post_por_pagina - $post_por_pagina: 0;
    $sentencia = $conexion->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM articulos LIMIT $inicio, $post_por_pagina"); 
    $sentencia->execute();
    return $sentencia->fetchAll();

}
    
asked by jonatan 13.02.2017 в 15:36
source

1 answer

2

When the connection fails, you receive a false response, then your connection is not a PDO or MySQLi object, but a Boolean.

You have to verify the value of the $ connection object.

<?php
$conexión = mysqli_connect("127.0.0.1", "mi_usuario", "mi_contraseña", "mi_bd");

if (!$conexión) {
    echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
    echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL;
    echo "error de depuración: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

(example taken from mysqli-connect )

    
answered by 13.02.2017 / 15:40
source