php mysql foreach is bad pardics 3f

Solutions on MaxInterview for php mysql foreach is bad pardics 3f by the best coders in the world

showing results for - "php mysql foreach is bad pardics 3f"
Yestin
22 Aug 2020
1<?php
2# Connection
3$host    = "localhost";
4$db_user = "xxxx";
5$db_pw   = "xxxxx";
6$db_name = "xxxxx";
7try {
8    $connessione = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $db_pw);
9    $connessione->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10} catch(PDOException $e) {
11    echo "Errore:" .$e->getMessage();
12    die();
13}  
14
15# Data
16$file = file_get_contents($filejson);
17if (!function_exists('json_decode')) {
18    die('Il server non ha tale funzione');
19}   
20$result = json_decode($file, true);
21
22# Prepare and execute statement
23try {
24    $sql = 
25        "INSERT INTO ibl_Anag (TicketId,otherId,ClientId,Name,LName,MobPhone,Phone,address,mail)
26        VALUES (?,?,?,?,?,?,?,?,?)";
27    $stmt = $connessione->prepare($sql);
28    foreach ($result["Contacts"] as $row) {
29        $ticketId = $row["TicketId"];
30        $otherId  = $row["otherId"];
31        $clientId = $row["ClientId"];
32        $name     = $row["Name"];
33        $lname    = $row["LName"];
34        $mobPhone = $row["Phone"];
35        $phone    = $row["Phone"];
36        $address  = $row["ADDRESS"];
37        $mail     = $row["mail"];
38        $stmt->BindParam(1, $ticketId);
39        $stmt->BindParam(2, $otherId); 
40        $stmt->BindParam(3, $clientId);
41        $stmt->BindParam(4, $name);    
42        $stmt->BindParam(5, $lname);   
43        $stmt->BindParam(6, $mobPhone);
44        $stmt->BindParam(7, $phone);   
45        $stmt->BindParam(8, $address);
46        $stmt->BindParam(9, $mail);    
47        if (!$stmt->execute()) {
48            echo "la insert non ha funzionato";
49        }
50    }                       
51} catch(PDOException $e) {
52    echo "Errore:" .$e->getMessage();
53    die();
54}  
55?>
56
similar questions
queries leading to this page
php mysql foreach is bad pardics 3f