Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php mysql foreach is bad pardics ?

<?php
# Connection
$host    = "localhost";
$db_user = "xxxx";
$db_pw   = "xxxxx";
$db_name = "xxxxx";
try {
    $connessione = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $db_pw);
    $connessione->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo "Errore:" .$e->getMessage();
    die();
}  

# Data
$file = file_get_contents($filejson);
if (!function_exists('json_decode')) {
    die('Il server non ha tale funzione');
}   
$result = json_decode($file, true);

# Prepare and execute statement
try {
    $sql = 
        "INSERT INTO ibl_Anag (TicketId,otherId,ClientId,Name,LName,MobPhone,Phone,address,mail)
        VALUES (?,?,?,?,?,?,?,?,?)";
    $stmt = $connessione->prepare($sql);
    foreach ($result["Contacts"] as $row) {
        $ticketId = $row["TicketId"];
        $otherId  = $row["otherId"];
        $clientId = $row["ClientId"];
        $name     = $row["Name"];
        $lname    = $row["LName"];
        $mobPhone = $row["Phone"];
        $phone    = $row["Phone"];
        $address  = $row["ADDRESS"];
        $mail     = $row["mail"];
        $stmt->BindParam(1, $ticketId);
        $stmt->BindParam(2, $otherId); 
        $stmt->BindParam(3, $clientId);
        $stmt->BindParam(4, $name);    
        $stmt->BindParam(5, $lname);   
        $stmt->BindParam(6, $mobPhone);
        $stmt->BindParam(7, $phone);   
        $stmt->BindParam(8, $address);
        $stmt->BindParam(9, $mail);    
        if (!$stmt->execute()) {
            echo "la insert non ha funzionato";
        }
    }                       
} catch(PDOException $e) {
    echo "Errore:" .$e->getMessage();
    die();
}  
?>
Comment

PREVIOUS NEXT
Code Example
Php :: vendor folder command for custom errors laravel 
Php :: Pasar el email de recuperar contraseña de laravel a español 
Php :: what is post_class() 
Php :: letzten 3 zeichen aus einem string entfernen php 
Php :: php list all files in directory and subdirectories 
Php :: event handler with worker laravel 
Php :: php ?: 
Php :: base64_decode 
Php :: lowercase in array php 
Php :: ?? operator in php laravel 
Php :: php multiple array to single array 
Php :: how to get the ip address of the client in php 
Php :: laravel jobs tutorial 
Php :: how to append one array to another array in php 
Php :: php abstract class static method 
Php :: json decode php array 
Php :: php check if passwords match 
Php :: Append a text string to WooCommerce product title loop 
Java :: javafx vm arguments 
Java :: how to set current date in android studio 
Java :: how to clear terminal in java 
Java :: create a random char java 
Java :: age in java 
Java :: java stream collect to arraylist 
Java :: how to get an array as input in java 
Java :: open webpage android studio 
Java :: show dialog fragment from adapter 
Java :: join array java 
Java :: reading in lines from a file java 
Java :: read jar manifest 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =