MS SQL Server Concepts and Programming Question: Download MS SQL Server PDF

PHP ODBC - How To Insert Data into an Existing Table?

Tweet Share WhatsApp

Answer:

If you want to insert a row of data into an existing table, you can use the INSERT INTO statement as shown in the following sample script:

<?php
$con = odbc_connect('ggl_SQL_SERVER','sa','GlobalGuideLine');

$sql = "INSERT INTO ggl_links (id, url) VALUES ("
. " 101, 'GlobalGuideLine.com')";
$res = odbc_exec($con, $sql);
if (!$res) {
print("SQL statement failed with error: ");
print(odbc_error($con).": ".odbc_errormsg($con)." ");
} else {
print("One data row inserted. ");
}

$sql = "INSERT INTO ggl_links (id, url) VALUES ("
. " 102, 'GlobalGuideLine.com')";
$res = odbc_exec($con, $sql);
print("One data row inserted. ");

odbc_close($con);
?>

If you run this script, two data rows should be inserted into the table. And you will get:

One data row inserted.
One data row inserted.


Download MS SQL Server PDF Read All 394 MS SQL Server Questions
Previous QuestionNext Question
PHP ODBC - How To Create a New Table?PHP ODBC - How To Insert Multiple Rows with a subquery?