What is the best way to insert multiple rows in PHP PDO MYSQL?

You have at least these two options: $rows = [(1,2,3), (4,5,6), (7,8,9) … ]; $sql = “insert into `table_name` (col1, col2, col3) values (?,?,?)”; $stmt = $db->prepare($sql); foreach($rows as $row) { $stmt->execute($row); } OR: $rows = [(1,2,3), (4,5,6), (7,8,9) … ]; $sql = “insert into `table_name` (col1, col2, col3) values “; $paramArray = array(); $sqlArray … Read more

INSERT COMMAND :: ERROR: column “value” does not exist

Character constants need single quotes. Use: INSERT INTO users(user_name, name, password,email) VALUES (‘user2′,’first last’,’password1′, ‘[email protected]’ ); See the manual: postgresql.org/docs/current/static/… Note: After I encountered the same problem and almost missed the answer that exists in this page (at the comments section), thanks to @a-horse-with-no-name – I’ve posted this answer

C# with MySQL INSERT parameters

You may use AddWithValue method like: string connString = ConfigurationManager.ConnectionStrings[“default”].ConnectionString; MySqlConnection conn = new MySqlConnection(connString); conn.Open(); MySqlCommand comm = conn.CreateCommand(); comm.CommandText = “INSERT INTO room(person,address) VALUES(@person, @address)”; comm.Parameters.AddWithValue(“@person”, “Myname”); comm.Parameters.AddWithValue(“@address”, “Myaddress”); comm.ExecuteNonQuery(); conn.Close(); OR Try with ? instead of @, like: string connString = ConfigurationManager.ConnectionStrings[“default”].ConnectionString; MySqlConnection conn = new MySqlConnection(connString); conn.Open(); MySqlCommand comm = conn.CreateCommand(); … Read more

PHP MYSQL UPDATE if Exist or INSERT if not?

I believe you are looking for the following syntax: INSERT INTO <table> (field1, field2, field3, …) VALUES (‘value1’, ‘value2′,’value3′, …) ON DUPLICATE KEY UPDATE field1=’value1′, field2=’value2′, field3=’value3’, … Note: With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row … Read more

Inserting data to table (mysqli insert) [duplicate]

Warning: Never ever refer to w3schools for learning purposes. They have so many mistakes in their tutorials. According to the mysqli_query documentation, the first parameter must be a connection string: $link = mysqli_connect(“localhost”,”root”,””,”web_table”); mysqli_query($link,”INSERT INTO web_formitem (`ID`, `formID`, `caption`, `key`, `sortorder`, `type`, `enabled`, `mandatory`, `data`) VALUES (105, 7, ‘Tip izdelka (6)’, ‘producttype_6’, 42, 5, 1, … Read more