1 頁 (共 1 頁)

mod_harbour and TMySQL

發表於 : 2024-06-14, 11:54
admin
Use TMySQL:
Desktop app vs Web app.

代碼: 選擇全部

<?prg
zzz()
function zzz()
  LOCAL oServer
  LOCAL oQry
  LOCAL nI
  LOCAL cFile    := AP_FileName()
  LOCAL cMainDir := cFilePath(cFile) // 尾端有 '/'
  LOCAL oDB, xHrb, hJson := hb_hash()

  AP_SetContentType( "text/html; charset=utf-8" )

  ?? "debug-begin...:"+cMainDir

  ? '傳遞參數: '+valToChar(AP_Args()) // hash
  ? '接收資料 GET: '+valToChar( AP_GetPairs()) // hash
  hData := AP_GetPairs()	// 取得 'GET' data
  If ! Empty(hData) .And. hb_hHasKey( hData, 'a')
     ? 'GET data:'+hData['a']+'/type:'+ValType(hData['a'])
  EndIf
  ? 'POST: '+valToChar( AP_PostPairs()) // hash
  ? 'HTTPS:'+valToChar( AP_GetEnv( "HTTPS" ))
  ? 'HTTP:'+valToChar( AP_GetEnv( "HTTP" ))

  Set( _SET_DATEFORMAT, "yyyy-mm-dd" )

  Do While .T.
  	//
  	oServer := TMySQLServer():New( "localhost", "root", "xxxxxxxx" )
  	IF oServer:NetErr()
  	   ? "mySQL connect fail!!"
  	   Exit
  	ELSE
  	   ? "mySQL connect success!!"
  	ENDIF
  	
  	oServer:SelectDB( "ss_test" )
  	IF oServer:NetErr()
  	   ? "mySQL select db fail!!"
  	   Exit
  	ELSE
  	   ? "mySQL select db success!!"
  	ENDIF
  	
  	IF oServer:SetChar('utf8') != 0
  	   ? "錯誤!資料庫設定編碼錯誤:[set names utf8]無法使用!"
  	   Exit
  	ENDIF
  	
  	oQry := oServer:Query( "SELECT * from prd" )
  	
  	IF oQry:RecCount() > 0
  	   ? "found data..."
  	   For nI := 1 To oQry:RecCount()
  	       ? 'PRDID:'+hb_ntos(oQry:FieldGet('PRDID'))+'/'+;
  	         'PD_NAM:'+oQry:FieldGet('PD_NAM')+'/'+;
  	         'utf8 Len:'+hb_ntos( hb_utf8Len( Trim( oQry:FieldGet('PD_NAM')) ))+'/'+;
  	         'big5 Len:'+hb_ntos( Len( Trim( oQry:FieldGet('PD_NAM')) ))
  	       oQry:Skip()
  	   Next nI
  	ELSE
  	   ? "not found data!!"
  	ENDIF
  	oQry:End()
  	Exit
  EndDo
  //
  If ValType( oServer ) == 'O'
     oServer:Destroy()
  EndIf
  //
return
?>