Answers

Question and Answer:

  Home  MS SQL Server

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

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.

 151 views

More Questions for you: