[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)) {
……
……
……
}

Leave a Comment

[PHP] Convertin String to Time and incrementing date by one day…

Converting a date string to time object
===============================
$sUnixDateTime = strtotime($sDate)

Incrementing date by one day, result will be returned as a date object
========================================================
$sUnixDateTime = mktime(0, 0, 0, date(“m”, $sUnixDateTime), date(“d”, $sUnixDateTime)+1, date(“Y”, $sUnixDateTime));

Leave a Comment

Getting formatted date and time string in C Programming

wchar_t wszTime[101];
time_t t = time(NULL);
wcsftime(wszTime, sizeof(wszTime), _T(“%Y/%m/%d : %H:%M:%S”), localtime(&t));
wprintf(_T(“%s”), wszTime);

Leave a Comment

Handling OnCtlColor()

HBRUSH CPlayBackQueryDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

if(nCtlColor == CTLCOLOR_DLG)
{
return gbrushDlgBkGround;
}
else if(nCtlColor == CTLCOLOR_EDIT)
{
pDC->SetTextColor(guiEditTextColor());
pDC->SetBkColor(gclrEditBk);
return gbrEditBk;
}
else if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
return gbrBlueRectBk;
}
else
return gbrushDlgBkGround;
// TODO: Return a different brush if the default is not desired
return hbr;
}

Leave a Comment

Handling database

    try
{
CString sConnection;

sConnection.Format(“DRIVER={PostgreSQL ANSI};SERVER=%s;port=%s;DATABASE=%s;UID=%s;PWD=%s;”, gstGlobalValues.pgsqlIP, gstGlobalValues.pgsqlPort, gstGlobalValues.pgsqlUserName, gstGlobalValues.pgsqlUserName, gstGlobalValues.pgsqlPassword );
m_db.OpenEx(sConnection);
}
catch(CDBException *e)
{
MessageBox(“Unable to connect with PostgreSQL.\n\nThe error message from PostgreSQL is \n\n”+e->m_strError,”Error message from PostgreSQL”, MB_ICONINFORMATION);
e->Delete();
EndDialog(IDCANCEL);
return TRUE;
}

{
CRecordset rs(&m_db);
CString sQuery;

sQuery.Format(“select min(tran_date), max(tran_date) from %s;”, frTRANSACTION_TBL);

try
{
rs.Open(AFX_DB_USE_DEFAULT_TYPE, sQuery);

if(rs.GetRecordCount() <= 0)
{
MessageBox(“\nNo test transaction found in database.\t\n”, “Testing not yet done”, MB_ICONEXCLAMATION);
EndDialog(IDCANCEL);
return TRUE;
}

i = 0;
rs.GetFieldValue(i, sQuery);
m_stSysTime1.wYear = atoi(sQuery.Mid(0,4));
m_stSysTime1.wMonth = atoi(sQuery.Mid(5,2));
m_stSysTime1.wDay = atoi(sQuery.Mid(8,2));

i++;
rs.GetFieldValue(i, sQuery);
m_stSysTime2.wYear = atoi(sQuery.Mid(0,4));
m_stSysTime2.wMonth = atoi(sQuery.Mid(5,2));
m_stSysTime2.wDay = atoi(sQuery.Mid(8,2));

rs.Close();
}
catch(CDBException *e)
{
MessageBox(“Unable to fetch test transaction records from PostgreSQL.\n\nThe error message from PostgreSQL is \n\n”+e->m_strError,”Error message from PostgreSQL”, MB_ICONINFORMATION);
e->Delete();
EndDialog(IDCANCEL);
return TRUE;
}

}

Leave a Comment

VC++ Buddies

Leave a Comment

« Newer Posts