13

Insert a multidimensional array with MySQLI Prepared Statements?

 3 years ago
source link: https://www.codesd.com/item/insert-a-multidimensional-array-with-mysqli-prepared-statements.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Insert a multidimensional array with MySQLI Prepared Statements?

advertisements

Ive researched a lot on how to insert a multidimensional array into MySQL using mysqli prepared statements. The old way looked like this:

EcsaN.png

This would build a long query with all the values. How do i replicate this but in mysqli prepared statements?, ive found so many contradicting posts regarding this, anyone who can show a working example if possible?

Thanks a lot in advance.


foreach ($reg as $row){

$query = "INSERT INTO region (a1, b1, c1) values('$row[0]','$row[1]','$row[2]',)"; $result = mysqli_query($main, $query);

Related Articles

inserting a multidimensional array into mysql

i want to insert data from multidimensional array into mysql but while looping it loop more than necessary. i mean i want it to enter 6 records but i got many records. i knew i have problem with my mysql query location but have tried many techniques

Iterate Multidimensional Array with Nested Foreach Statement

I think this might be a pretty simple question, but I haven't been able to figure it out yet. If I've got a 2-dimensional array like so: int[,] array = new int[2,3] { {1, 2, 3}, {4, 5, 6} }; What's the best way to iterate through each dimension of th

fail without error with mysqli prepare statement

I have these lines in a small php script : $sql = "UPDATE activation SET end = NOW(), deactivated_by = ? WHERE id=?;"; $stmt = $mysqli->prepare($sql); if(!$stmt) {die('prepare4 failed: ' . htmlspecialchars($mysqli->error));} But I get this

inner join will not work with mysqli prepared statement in php

I can't seem to get this statement or statements alike to work with prepared queries, the code works just fine below: $DBH = getDBH(); $stmt = $DBH->prepare("SELECT a.id, a.title, a.photo FROM tag t INNER JOIN tag_reference atx ON t.tag_id = atx.t

PHP & amp; MySQL: Prepared statements vs function for security and coding speed

This is more of a question of 'best practice' really. Currently coding a website back-end, and have heard the strong recommendations to use mysqli prepared statements, so have been doing that. However, in the past I've also been told the maxim 'work

How to extract everything in assoc array from a prepared statement?

I'm trying this code: if ($result = $this->mysqli->prepare("SELECT * FROM `mytable` WHERE `rows1`=?")) { $result->bind_param("i",$id); $result->execute(); while ($data = $result->fetch_assoc()) { $statistic[] = $data; }

MySQL, MySQLi, MySQL Prepared Statement or DOP?

from the past few days i have been following a lot of tutorials regarding different ways to interact with database. like the old MySQL way, MySQLi, MySQL prepared statement, PHP's PDO etc. i am still a new comer to the programming as it has been hard

php mysqli prepared statement using wildcards

I am trying to build this prepared statement: $sql = "SELECT * FROM entries WHERE"; $sql .= " title LIKE ? OR title LIKE ? OR title LIKE ? OR title LIKE ?"; $sql .= " OR content LIKE ? OR content LIKE ? OR content LIKE ? OR conten

How can I assign a variable with a prepared statement in a stored procedure?

I've put together a simple stored procedure in which two parameters are passed through to make it more dynamic. I've done this with a prepared statement in the "First Two Digits and Count of Records" section. What I'm not sure of is if I can mak

PHP mysqli prepared statement deleted zero

I tried switching over to PHP5 i think it is, with the use of mysqli prepared statements. It works fine, with everything else, but when it comes to numbers, for some reason it decides to delete the zero on the end of the value of a number. For exampl

How does php / mysqli (prepared statements + bind params) protect against SQL Injection?

How php/mysqli ( with prepared statements + bind params ) protect against SQL Injection ? Mysqli applies only "real_escape_string" for variables or do something else? May i say that the function below is totally useless when using mysqli + prepa

Sort the multidimensional array with qsort in C

I'm trying to sort multidimensional array with qsort, but the result is nonsense.. My code (excerpt): #include <stdio.h> #include <stdlib.h> int srovnejVelikost(const void *p1, const void *p2) { const long int (*a)[5] = p1; const long int (*b)

Initialization of multidimensional arrays with loop enhancement in java

I'm just playing around with my code, and was wondering if initializing a multidimensional array with the enhanced for loop is possible. How do I fix this? double[][] array2 = new double[2][5]; int b=1; counter=0; for(double[] x:array2) { for(double

Table difference for a multidimensional array with a single array in php

I want difference of multidimensional array with single array. I dont know whether it is possible or not. But my purpose is find diference. My first array contain username and mobile number array1 ( array(lokesh,9687060900), array(mehul,9714959456),

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK