Collections:
PHP ODBC - Inserting Multiple Rows with a Subquery
PHP ODBC - How To Insert Multiple Rows with a subquery?
✍: Guest
If want to insert rows into a table based on data rows from other tables, you can use a subquery inside the INSERT statement as shown in the following script example:
<?php
$con = odbc_connect('FYI_SQL_SERVER','sa','FYIcenter');
$sql = "INSERT INTO fyi_links"
. " SELECT id+1000, REVERSE(url), notes, counts, time"
. " FROM fyi_links";
$res = odbc_exec($con, $sql);
if (!$res) {
print("SQL statement failed with error:\n");
print(odbc_error($con).": ".odbc_errormsg($con)."\n");
} else {
print("Multiple rows inserted.\n");
}
odbc_close($con);
If you run this script, the table should have 4 rows now. And you will get:
Multiple rows inserted
⇒ PHP ODBC - odbc_num_rows() - Number of Affected Rows
⇐ PHP ODBC - Inserting Data into an Existing Table
⇑ SQL Server FAQs - PHP ODBC Functions - Managing Tables and Data Rows
2024-05-29, 2100🔥, 0💬
Popular Posts:
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How To Create a Table Index in Oracle? If you have a table with a lots of rows, and you know that on...
What Happens If the UPDATE Subquery Returns Multiple Rows in SQL Server? If a subquery is used in a ...
How To Generate CREATE VIEW Script on an Existing View in SQL Server? If you want to know how an exi...