PHP ODBC - How To Create a New Table?
Submitted by: AdministratorIf you want to create a table in the database connected through a ODBC DSN, you can run the CREATE TABLE SQL statement using the odbc_exec() function, as shown in the following sample script:
<?php
$con = odbc_connect('ggl_SQL_SERVER','sa','GlobalGuideLine');
# creating a new table
$sql = "CREATE TABLE ggl_links ("
. " id INT NOT NULL"
. ", url VARCHAR(80) NOT NULL"
. ", notes VARCHAR(1024)"
. ", counts INT"
. ", time DATETIME"
. ")";
$res = odbc_exec($con, $sql);
if (!$res) {
print("Table creation failed with error: ");
print(odbc_error($con).": ".odbc_errormsg($con)." ");
} else {
print("Table ggl_links created. ");
}
odbc_close($con);
?>
Submitted by: Administrator
<?php
$con = odbc_connect('ggl_SQL_SERVER','sa','GlobalGuideLine');
# creating a new table
$sql = "CREATE TABLE ggl_links ("
. " id INT NOT NULL"
. ", url VARCHAR(80) NOT NULL"
. ", notes VARCHAR(1024)"
. ", counts INT"
. ", time DATETIME"
. ")";
$res = odbc_exec($con, $sql);
if (!$res) {
print("Table creation failed with error: ");
print(odbc_error($con).": ".odbc_errormsg($con)." ");
} else {
print("Table ggl_links created. ");
}
odbc_close($con);
?>
Submitted by: Administrator
If you run this script for the first time and there is no existing table called ggl_links in the database, you will get:
Table ggl_links created.
If you run it again, you will get:
Table creation failed with error:
S0001: [Microsoft][ODBC SQL Server Driver][SQL Server]
There is already an object named 'ggl_links' in the
database.
Submitted by: Administrator
Table ggl_links created.
If you run it again, you will get:
Table creation failed with error:
S0001: [Microsoft][ODBC SQL Server Driver][SQL Server]
There is already an object named 'ggl_links' in the
database.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Is a Transact-SQL Statement Batch in MS SQL Server? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | How To Get the Definition of a View Out of the SQL Server? |
☺ | How To Use Subqueries with the EXISTS Operators in MS SQL Server? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |