php47

Curso de PHP🐘 y MySql🐬 [47.- Exportar e importar datos de MySQL]

Importar productos a nuestra tabla desde excel con ayuda de PHPMyAdmin.
Archivo excel: https://docs.google.com/spreadsheets/d/1U7jclMxhr8CqCYtQZuqp2YFU5iKiT5yhO53ruYFvq00/edit?usp=sharing

Manipular tablas con:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
RENAME TABLE TABLE 2 TO productos;
create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5));
RENAME TABLE TABLE 2 TO productos; create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5));
RENAME TABLE TABLE 2 TO productos;
create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5));

Crear querys de importación.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5));
insert into misProductos (nombre,precio,categoria,existencia) values
('coca',10,'bebidas',5),
('pepsi',10,'bebidas',6),
('sopa',15,'alimentos',7);
create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5)); insert into misProductos (nombre,precio,categoria,existencia) values ('coca',10,'bebidas',5), ('pepsi',10,'bebidas',6), ('sopa',15,'alimentos',7);
create table misProductos (nombre varchar (50),precio float,categoria varchar (50),existencia int(5));
insert into misProductos (nombre,precio,categoria,existencia) values
('coca',10,'bebidas',5),
('pepsi',10,'bebidas',6),
('sopa',15,'alimentos',7);

Exportar tablas de una Base de datos a otra con PHPMyAdmin.

Codigo: https://github.com/programadornovato/php/commit/2721efd8fb67a5918f20062b87f764fb6ac2f693

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="en">
<head>
<title>Tutorial Mysql</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function() {
$('#tablaAutos').DataTable();
});
</script>
</head>
<body>
<?php
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
include_once "db_empresa.php";
$conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
if ($conexion == false) {
die("Error de conexion a Mysql con el codigo: " . mysqli_connect_errno() .
"<br>" . mysqli_connect_error());
}
$sql = "SELECT
`id`,
`nombre`,
`precioCompra`,
`precioVenta`,
`fechaCompra`,
`categoria`,
`unidadesEnExistencia`
FROM `productos`
WHERE
unidadesEnExistencia=0
and
categoria='Carnes'
;
";
$resultSet = mysqli_query($conexion, $sql);
?>
<div class="container mt-5">
<div class="row">
<div class="col-12">
<table class="table table-striped" id="tablaAutos">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Nombre</th>
<th scope="col">Precio</th>
<th scope="col">Categoria</th>
<th scope="col">Existencia</th>
</tr>
</thead>
<tbody>
<?php
$contador = 1;
while ($row = mysqli_fetch_row($resultSet)) {
?>
<tr>
<th scope="row"><?php echo $row[0]; ?></th>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[5]; ?></td>
<td><?php echo $row[6]; ?></td>
</tr>
<?php
$contador++;
}
mysqli_close($conexion);
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
<!doctype html> <html lang="en"> <head> <title>Tutorial Mysql</title> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script> <script> $(document).ready(function() { $('#tablaAutos').DataTable(); }); </script> </head> <body> <?php ini_set("display_errors", 1); ini_set("display_startup_errors", 1); include_once "db_empresa.php"; $conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database); if ($conexion == false) { die("Error de conexion a Mysql con el codigo: " . mysqli_connect_errno() . "<br>" . mysqli_connect_error()); } $sql = "SELECT `id`, `nombre`, `precioCompra`, `precioVenta`, `fechaCompra`, `categoria`, `unidadesEnExistencia` FROM `productos` WHERE unidadesEnExistencia=0 and categoria='Carnes' ; "; $resultSet = mysqli_query($conexion, $sql); ?> <div class="container mt-5"> <div class="row"> <div class="col-12"> <table class="table table-striped" id="tablaAutos"> <thead> <tr> <th scope="col">Id</th> <th scope="col">Nombre</th> <th scope="col">Precio</th> <th scope="col">Categoria</th> <th scope="col">Existencia</th> </tr> </thead> <tbody> <?php $contador = 1; while ($row = mysqli_fetch_row($resultSet)) { ?> <tr> <th scope="row"><?php echo $row[0]; ?></th> <td><?php echo $row[1]; ?></td> <td><?php echo $row[3]; ?></td> <td><?php echo $row[5]; ?></td> <td><?php echo $row[6]; ?></td> </tr> <?php $contador++; } mysqli_close($conexion); ?> </tbody> </table> </div> </div> </div> </body> </html>
<!doctype html>
<html lang="en">

<head>
    <title>Tutorial Mysql</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
    <script>
        $(document).ready(function() {
            $('#tablaAutos').DataTable();
        });
    </script>
</head>

<body>
    <?php
    ini_set("display_errors", 1);
    ini_set("display_startup_errors", 1);
    include_once "db_empresa.php";
    $conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
    if ($conexion == false) {
        die("Error de conexion a Mysql con el codigo: " . mysqli_connect_errno() .
            "<br>" . mysqli_connect_error());
    }
    $sql = "SELECT 
    `id`, 
    `nombre`, 
    `precioCompra`, 
    `precioVenta`, 
    `fechaCompra`, 
    `categoria`, 
    `unidadesEnExistencia` 
    
    FROM `productos`
    
    WHERE 
    unidadesEnExistencia=0
    and
    categoria='Carnes'
    ;
    ";
    $resultSet = mysqli_query($conexion, $sql);
    ?>
    <div class="container mt-5">
        <div class="row">
            <div class="col-12">
                <table class="table table-striped" id="tablaAutos">
                    <thead>
                        <tr>
                            <th scope="col">Id</th>
                            <th scope="col">Nombre</th>
                            <th scope="col">Precio</th>
                            <th scope="col">Categoria</th>
                            <th scope="col">Existencia</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        $contador = 1;
                        while ($row = mysqli_fetch_row($resultSet)) {
                            ?>
                            <tr>
                                <th scope="row"><?php echo $row[0]; ?></th>
                                <td><?php echo $row[1]; ?></td>
                                <td><?php echo $row[3]; ?></td>
                                <td><?php echo $row[5]; ?></td>
                                <td><?php echo $row[6]; ?></td>
                            </tr>
                        <?php
                            $contador++;
                        }
                        mysqli_close($conexion);
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>

</html>

🎦 Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS2Dvb-WNrAuDAXObB8GzJ0

Codigos en gdrive: https://drive.google.com/file/d/1tQwYvfL2jiUFc6beTWkOkGmXkq5zzFw2/view?usp=sharing
Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true

🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *