jump to navigation

Koneksi dari PHP ke Database MS SQL Server 23 October 2008

Posted by igenx in programming.
7 comments

Pertama dibutuhkan php_mssql.dll

File php_mssql.dll tersebut berada pada paket PHP pada directory extension atau ext. Sebelum menggunakan extension SQL Server tersebut, Anda harus memodifikasi file php.ini karena biasanya file php_mssql.dll pada bagian extension masih di-disable atau diberi remark. Hilangkan tanda remark (;) yang ada pada baris yang berisi “extension=php_mssql.dll” kemudian simpan kembali file php.ini tersebut dan kemudian restart kembali service Apache Anda dengan mengetikkan perintah “net stop apache” dan kemudian “net start apache” dari DOS prompt Anda.

Untuk menguji apakah extension PHP php_mssql.dll sudah di-load dengan sempurna, maka Anda bisa memeriksanya dengan fungsi phpinfo()
Pada PHP telah tersedia fungsi untuk melakukan koneksi ke SQL Server yaitu fungsi mssql_connect. Fungsi-fungsi lainnya juga tersedia misalnya untuk melakukan query dan lain sebagainya (mssql_query(), mssql_fetch_array() dan lain sebagainya).

Berikut ini adalah contoh koneksi ke SQL Server dengan fungsi mssql_connect().

<?php
  if (mssql_connect('localhost', 'sa', '')) {
    echo 'Koneksi ke SQL Server sukses';
   }
  else {
    echo 'Koneksi ke SQL Server gagal';
  }
?>

Koneksi ke SQL Server
dan kemudian akan
menampilkan informasi
seputar server SQL Server
dengan memanggil
stored procedure
sp_server_info.

<?php
  if ($conn = mssql_connect('localhost', 'sa', '')) {
    $result = mssql_query("EXEC sp_server_info", $conn);
    while ($row = mssql_fetch_array($result)) {
      echo $row['attribute_name'] . ': '
      . $row['attribute_value'] . '<br>';
    }
  }
  else {
    echo 'Koneksi ke SQL Server gagal';
  }
?>

untuk SQL Server 2005 gunakan driver dari
Microsoft sendiri
http://www.microsoft.com/downloads/
    details.aspx?familyid=85f99a70-
    5df5-4558-991f-8aee8506833c&
    displaylang=en

sumber penting :
PHP Manual
http://blogs.msdn.com/sqlphp/
http://www.phpindonesia.com/
http://devzone.zend.com/public/view

How to print all files in a folder in a single command? 22 October 2008

Posted by igenx in tips and tricks.
add a comment

We can print one document in Windows XP. But how to we print all files in the folders? Ok. If one folder has 10 files we can open all files and then give print command. If 100 files are there and you have to take a printout of all of them what can we do? Here only notepad comes to our help here we can write a batch file and command it to print from a right place.
Lets see briefly how is this done.

First of all open note pad, through Start, All Programs, Accessories, Notepad then type the following code without fault.

@echo off

dir%1/-p/o: gin>

“%temp%\listing”

Start/wnotepad/p”%temp%\listing”

Del”%temp%%\listing”

exit

Save the file as printdir.bat, then save it in c:\windows folder. A small tip: – you can save this file in any name but you must give the extension as .bat only. Now you have successfully created a file to print. Now, let’s see how to print all files in a folder,

1) First double click the My Computer icon.
2) Select Folder options from the Tools menu
3) Then Click File types tab, it will be in the upper side of the screen.
4) You will find a file type below” Registered file types”
5) Select it and click Advanced Tab
6) This opens Edit File Type. In this you can see a button “New” click it
7) New action dialog box opens
8)Type print directory in action tab
9) Browse for c:\windows\printdir.bat through browse button at application used to perform action
10) Click ok and close all the dialog boxes

If lot of files is to be printed we can create a folder and put them inside it, now right click on the folder and select print directory option in it, if you select this all files in the folder will be printed.

Regedit.exe & Regedt32.exe, Whats the difference 22 October 2008

Posted by igenx in Uncategorized.
add a comment

Have you ever noticed that there are two versions of the Registry Editor on your computer? Ever wondered why? Well let me just give you a little insight!

It all depends on your Operating System. If you have Windows 2000 :

Regedit.exe

Regedit.exe is included with Windows NT 4.0 and Windows 2000 primarily for its search capability. You can use Regedit.exe to make changes in the Windows NT 4.0 and Windows 2000 registry, but you cannot use it to view or edit all functions or data types on Windows NT 4.0 and Windows 2000.

The following limitations exist in the Regedit.exe version that is included with Windows NT 4.0 and Windows 2000:

You cannot set the security for registry keys.
You cannot view, edit, or search the value data types <>REG_EXPAND_SZ and <>REG_MULTI_SZ. If you try to view a <>REG_EXPAND_SZ value, Regedit.exe displays it as a binary data type. If you try to edit either of these data types, Regedit.exe saves it as <>REG_SZ, and the data type no longer performs its intended function.
You cannot save or restore keys as hive files.
Microsoft recommends that you use Regedit.exe only for its search capabilities on a Windows NT 4.0-based or Windows 2000-based computer.

Regedt32.exe

Regedt32.exe is the configuration editor for Windows NT 4.0 and Windows 2000. Regedt32.exe is used tomodify the Windows NT configuration database, or the Windows NTregistry. This editor allows you to view or modify the Windows NT registry.The editor provides views of windows that represent sections of theregistry, named hives. Each window displays two sections. On the leftside, there are folders that represent registry keys. On the right side,there are the values associated with the selected registry key. Regedt32 isa powerful tool, and you must use it with extreme caution when you changeregistry values. Missing or incorrect values in the registry can make theWindows installation unusable.

Note: Unlike Regedit.exe, Regedt32.exe does not support importing and exporting registration entries (.reg) files.

Or..Windows XP and Windows Server 2003

Regedit.exe

Regedit.exe is the configuration editor for Windows XP and Windows Server 2003. Regedit.exe is used tomodify the Windows NT configuration database, or the Windows NTregistry. This editor allows you to view or modify the Windows NT registry. It supports setting security on registry keys, viewing and editing <>REG_EXPAND_SZ and <>REG_MULTI_SZ, and saving and restoring hive files.On the leftside, there are folders that represent registry keys. On the right side,there are the values associated with the selected registry key. Regedit isa powerful tool. You must use extreme caution when you use it to changeregistry values. Missing or incorrect values in the registry can make theWindows installation unusable.

Regedt32.exe

In Windows XP and Windows Server 2003, Regedt32.exe is a small program that just runs Regedit.exe.

VB/MySQL Datatypes 22 October 2008

Posted by igenx in programming.
add a comment
MySQL Datatype Length VB6 Datatype Length Notes
TINYINT -128 to 127 integer -32,768 to 32,767 *
TINYINT UNSIGNED 0 to 255 byte 0 to 255
SMALLINT -32,768 to 32,767 integer -32,768 to 32,767
SMALLINT UNSIGNED 0 to 65,535 long -2,147,483,647 to 2,147,483,647 *
MEDIUMINT -8,388,608 to 8,388,607 long -2,147,483,647 to 2,147,483,647 *
MEDIUMINT UNSIGNED 0 to 16,777,215 long -2,147,483,647 to 2,147,483,647 *
INT -2,147,483,647 to 2,147,483,647 long -2,147,483,647 to 2,147,483,647
INT UNSIGNED 0 to 4,294,967,295 double 64 Bit 1*
BIGINT 64 Bit N/A N/A 2
FLOAT 32 Bit Floating Point single 32 Bit Floating Point
DOUBLE 64 Bit Floating Point double 64 Bit Floating Point
DECIMAL Variable Floating Point double 64 Bit Floating Point 3*
CHAR 1 to 255 Characters string 1 to Approx. 2,000,000,000 Characters *
VARCHAR 1 to 255 Characters string 1 to Approx. 2,000,000,000 Characters *
TINYTEXT 1 to 255 Characters string 1 to Approx. 2,000,000,000 Characters *
TEXT 1 to 65535 Characters string 1 to Approx. 2,000,000,000 Characters 4*
MEDIUMTEXT 1 to 16,777,215 Characters string 1 to Approx. 2,000,000,000 Characters 4*
LONGTEXT 1 to 4,294,967,295 Characters N/A N/A 5
all BLOB types 1 to 4,294,967,295 Bytes Variant Varies 6
DATE Date without Time date Date and Time value *
DATETIME Date and Time date Date and Time value
TIMESTAMP Date and Time date Date and Time value
TIME Time date Date and Time value *
YEAR Year integer -32,768 to 32,767 *
ENUM Enumeration of Value Set string 1 to Approx. 2,000,000,000 Characters *
SET Set of Values string 1 to Approx. 2,000,000,000 Characters *

Notes:

1) There is no such thing as a 32 bit unsigned integer in VB, so data must be stored in a double, which is actually a floating-point datatype, therefore, be careful to make sure that any value that you will be passing to MySQL is rounded off before you post it. The use of an UNSIGNED INT with VB6 is not reccomended, but you may have some luck with the larger integers of VB.NET.

2) BIGINT cannot be used with ADO, as it will cause errors, you can use the MyODBC option of 16384 (convert BIGINT to INT) to make them funnel down, but from what I understand your BIGINT is then limited to the size of an INT anyway. If a BIGINT is brought into a long, you will be ok up to the limit if the long datatype, after which your data will be corrupted.

3) DECIMAL can be passed to different VB6 Datatypes depending on how you define the DECIMAL column when creating the table. I personally would reccomend staying away from the DECIMAL type, as it takes 1 byte per digit for storage, you are better off using the appropriate numeric type.

4) If you have trouble loading TEXT and NEDIUMTEXT values from a recordset, make sure your max_allowed_packet parameter in MySQL is set appropriately high. I have been able to load text from a MEDIUMTEXT object up to the max_allowed_packet limit set in my server.

5) LONGTEXT data cannot be held in a string, and would need to be treated as a BLOB and written directly to a file using the BLOB handling methods. If using the stream object, change the stream type to adTypeText instead of adTypeBinary.

6) All blob data must be passed using either the getchunk/appendchunk method, or the ADO stream object. The variant in this case becomes a byte array, and cannot be handled directly by VB6.

VBMySQLDirect dan Crytal Report 22 October 2008

Posted by igenx in programming.
add a comment

Setelah aplikasi dibuat tentu ada laporan yang harus di tampilkan. Laporan  yang dibuat menggunakan Crytal Report 8.5, dan bisa aja di gunakan untuk versi-versi lain. Data yang diambil dari MySQL. Tetap menggunakan VBMySQLDirect, tapi ada tambahan kita gunakan juga VBMySQLCrystalDataSource.

Codes VBMySQLCrystalDataSource dapat kita ambil dari hasil download VBMySQLDirect.

Saya sarankan code di include dalam aplikasi aja, karena ada error yang akan terjadi jika kita jadikan class.

Dan tambahkan CRDataSource dalam reference nya “crsource.tlb”

Option Explicit
Private cSQL As String

Public Sub PreviewRpt(pcReportTitle As String, _
poReport As Object, poRs As MYSQL_RS, Optional pcTag As String = “”, Optional pbShownForm As Boolean = True)

Screen.MousePointer = vbHourglass
Dim oNewForm As frmRptViewer
Set oNewForm = New frmRptViewer
On Error Resume Next

With oNewForm
.Tag = pcReportTitle
.Caption = pcReportTitle
.Hide ‘~~berguna untuk laporan langsung di print tanpa preview

Dim pCrystal As VBMySQLCrystalDataSource
Set pCrystal = New VBMySQLCrystalDataSource
Set pCrystal.Recordset = poRs

poReport.Database.SetDataSource pCrystal
Set .crReport = poReport

.crv.ReportSource = .crReport
.crv.ViewReport
Do While .crv.IsBusy
DoEvents
Loop
.crv.Refresh

.crv.Me.Tag = pcTag
If pbShownForm Then .Show

End With

Screen.MousePointer = vbDefault
End Sub