[PHP] ODBC db functions

if($type == “mysql”){
$dsn = “Driver={MySQL ODBC 3.51 Driver};Server={$host};Database={$dbname};Port={$port};”;
}
else if($type == “mssql”){
$dsn = “Driver={SQL Server};Server={$host};Database={$dbname};Port={$port};”;
}
else if($type == “oracle”){
$dsn = “Driver={Microsoft ODBC for Oracle};Server={$host};Database={$dbname};Port={$port};”;
}
else if($type == “postgresql”){
$dsn = “Driver={PostgreSQL};Server={$host};Database={$dbname};Port={$port};”;
}

$odbc_connection=odbc_connect($dsn,$user,$pw,SQL_CUR_USE_ODBC);
odbc_exec($odbc_connection, “SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED”);

$sql = ‘INSERT INTO table (col1, col2, col3…) values (?,?,?… ) ‘;

$query = odbc_prepare($odbc_connection, $sql);

$result = odbc_execute($query, $insert_col_values); //$insert_col_values is array of string for each ?,?,?… in previopus statement.

$sql = “select from table_name where condition”;

while ($row = odbc_fetch_array($rs)) {
……
……
……
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: