Connection to mysql databases from HTML

1

Good afternoon I find the following error, I want to get a result of an SQL query to a local DB make a php file with the class and its function, and make an html file so that I can present it but it indicates me error // arhivo php for the connection

<?php

       class conexion {

        function restantes(){

                $enlace = mysql_connect('localhost', 'root', 'admin');
                if (!$enlace) {
                  die('No se pudo conectar : ' . mysql_error());
                    }


                    $bd_seleccionada = mysql_select_db('Kupon', $enlace);
                    if (!$bd_seleccionada) {
                         die ('No se puede usar Kupon : ' .mysql_error());
                            }

            $query = ' SELECT * FROM wp_postmeta ' ;
            $resultado = mysql_query($query);

            while ($fila = mysql_fetch_array($resultado)) {
            echo "$fila [meta_value]";

            }

            }
}

     ?>

in HTML I send it to call like this

<?php
include("conexion.php");
$enlace = new  conexion();
$enlace ->restantes();


 ?>

grcias

    
asked by Nathaniel Humberto Baldizon 03.10.2018 в 00:43
source

2 answers

1
<?php 
$s="localhost";
$bd="Kupon";
$u="root";
$p="admin";

$conexion=new mysqli($s, $u, $p, $bd);

if ($conexion -> connect_errno ) {


    echo "no Conectado";

}
else {


    $sql= "SELECT meta_value FROM wp_postmeta where  meta_key = '_stock' and post_id = 427 "; 
    $query=$conexion->query($sql); 
    if($query->num_rows>0){ 
    while($r=$query->fetch_array()){ 
    echo $r["meta_value"]; 
    echo "<br>";
    }
    }else{ 
    echo "No hay resultados";
    }
}

 ?>
    
answered by 03.10.2018 в 05:10
0
 PDO :: ERRMODE_EXCEPTION]; $ db = new PDO ($ dsn, $ db_user, $ db_pass, $ opt); try {  $ db = new PDO ($ host, $ db_user, $ db_pass, $ opt); } catch (PDOException $ Exception) {  echo $ Exception-> getMessage (); ? >     
answered by 03.10.2018 в 08:57