-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertConexion.php
More file actions
42 lines (34 loc) · 878 Bytes
/
insertConexion.php
File metadata and controls
42 lines (34 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
/*
**www.moleculax.com.ve
**https://github.com/moleculax
**Este es un ejemplo simple de como insertar datos usando PHP7.3 en mongoDB
*/
require 'vendor/autoload.php';
$cn = (new MongoDB\Client("mongodb://127.0.0.1:27017"))->dbname->BDequipos;
if($cn==true) {
echo ":.CONECT. DATOS INSERT.:<br>"; //porque no hubo excepciones
}
$client = new MongoDB\Client();
$nom = $client->BDequipos->conexion;
if($_POST) {
//datos a insertar
$seedData = array(
array(
'idpc' => $_POST['idpc'],
'ip' => $_POST['ip'],
'mac'=>$_POST['mac']
),
);
//inserta los datos
if ($nom->insertMany($seedData)){
echo"Datos Insertados correctamente";
header('Location: index.php');
}
else { echo"Fallo en inserción de datos.";}
}
else {
echo"No inserto los datos.";
}
?>