Some advices for common programmers problems

When trying to connect with SQL Server 2005 with PHP there might be a hard to find problem. PHP just return message: Couldn’t connect to sQL Server on … but there is no specific reason for this.

The first thing where I was looking for a reason was a connection string, precisely the server varaible value ($myServer) e.g.:






ini_set('display_errors', 1);
$myServer = "R400-JAC\CDN_OPTIMA";
$myUser = "sa";
$myPass = "password";
$myDB = "CDN_Demo";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query = "SELECT Knt_Nazwa1, Knt_Grupa
FROM [CDN].[Kontrahenci]";

//execute the SQL query and return records
$result = mssql_query($query);
var_dump($result);
$numRows = mssql_num_rows($result);
echo "

” . $numRows . ” Row” . ($numRows == 1 ? “” : “s”) . ” Returned

“;

//display the results
while($row = mssql_fetch_array($result))
{
echo “

  • ” . $row["Knt_Nazwa1"] . $row["Knt_Grupa"] .”
  • “;
    }
    //close the connection
    mssql_close($dbhandle);
    ?>

    So then I was trying to find if it is all about SQL Server, so was trying to change port for TCP/IP settings in SQL Surface Area configuration Manager. But all was right (settings was TCP/IP ADN Named Pipes).

    Then I launch SQL Server Browser Service which is by default not active. Still wrong. So then I set static port for TCP/IP settings in Server Configuration Manager which is explained here , and trying to change serverName variable for:
    - localhost:1443
    - localhost,50076 (which I found in registry)
    - 192.168.1.3:1433
    - R400-JAC\CDN_OPTIMA:1433
    - R400-JAC\CDN_OPTIMA:1503 (after change static port in SQL Service Manager)

    still nothing…

    Then at last I found that the reason was somewhere else. It was about ntwdblib.DLL which was in version 2000.2.8.0. This was not working. I download version 2000.80.194.0 and restart apache - so the script began to work.

    At last I return to previous settings in SQL Manager Utilites. Script still working so that was the reason.

    Jeżeli chcemy zrobić filmik prezentujący pulpit w akcji - można użyć vnc2swf (Linux).
    W ten sposób łączymy się z serwerem VNC

    vnc2swf -startrecording -geometry 1024x768 -depth 16 -framerate 5 test.swf 192.168.1.4:1.0

    Jeżeli serwerem jest Windows działające ustawienie wymaga na końcu podania w ten sposób:
    192.168.1.4:.0

    Jest też wersja dla Windows - używająca Pyhona pyvnc2swf
    Wymaga instalacji Python i Pygame - działa bez problemu

    1. Zainstaluj pakiet qemu (kqemu)
    2. Utwórz plik obrazu dysku, na którym będziesz mógł zainstalować system
    qemu-img create test.img 2G
    gdzie:
    test.img - nazwa pliku
    2G - rozmiar pliku
    3. Uruchom qemu wskazując napęd z płytą instalacyjną Windows za pomocą parametru -cdrom (można też wskazać plik obrazu ISO płyty instalacyjnej np. -cdrom image.iso)
    qemu -hda test.img -cdrom /dev/cdrom -boot d
    gdzie:
    -hda test.img - wskazuje stworzony wcześniej plik obrazu dysku
    -cdrom /dev/cdrom - wskazuje napęd z płytą instalacyjną Windows
    -boot d - nakazuje uruchomienie wirtualnego systemu z napędu d: (w tym przypadku z napędu CD)
    4. Po instalacji systemu Windows uruchom qemu
    qemu -hda test.img -boot c -m 192
    gdzie:
    -hda test.img - wskazuje plik obrazu dysku gdzie został zainstalowany Windows
    -boot c - uruchamia system z napędu c:
    -m 192 - ustala wielkość pamięci w MB

    Przydatne linki:

    http://www.szarp.com.pl/howto/howto/html/qemu.html


    http://fabrice.bellard.free.fr/qemu/user-doc.html


    http://compsoc.dur.ac.uk/~djw/qemu.html

    There are a limited ways to decrease file size, here is a couple from the Microsoft Mavens:
    File Size with Graphics
    By default, Word embeds pictures in a document.

    You can reduce the size of a file by linking a picture.

    In the Insert Picture dialog box (Insert menu, From File submenu), click the picture, click the arrow to the right of the Insert button, and then click Link to File.

    While you can’t edit the picture, you can see it in your document and print it when you print the document.

    Depending on your printer, printing directly to the printer may help.

    File Size Increases with EMF, PNG, GIF, or JPEG Graphics

    When you save a Word document containing an EMF, PNG, GIF, or JPEG graphic as a different file format (for example, Word 6.0/95 (*.doc) or Rich Text Format (*.rtf)), the file size of the document may dramatically increase.

    For example, a Word 2000 document containing a JPEG graphic saved as Word 2000 may have a file size of 45,568 bytes (44.5KB). However, when you save this file as Word 6.0/95 (*.doc) or Rich Text Format (*.rtf), the file size may grow to 1,289,728 bytes (1.22MB).

    This functionality is by design in Microsoft Word 2000. If an EMF, PNG, GIF, or JPEG graphic is inserted into a Word document, when the document is saved, two copies of the graphic are saved in the document. Graphics are saved in the applicable EMF, PNG, GIF, or JPEG format and are also converted to WMF (Windows Metafile) format.

    To prevent Word from saving two copies of the graphic in the document, and to reduce the file size of the document, add the ExportPictureWithMetafile=0 string value to the Windows registry using the following steps:

    1. Quit Word and all Microsoft Office programs.
    2. On the Windows Start menu, click Run.
    3. In the Open box, type regedit and click OK.
    4. Go to and select the following registry key:
    HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Word\Options

    NOTE: To access the Options registry key, you need to expand the various folders by either double-clicking each folder or clicking the plus sign (+) to the left of the folders.

    5. With the Options folder (key) selected, point to New on the Edit menu and click String Value.
    6. Type ExportPictureWithMetafile and press ENTER.

    NOTE: There are no spaces in the string value name.

    7. With the string value ExportPictureWithMetafile selected, click Modify on the Edit menu.
    8. In the Value data box, type 0.

    NOTE: Type a zero for the Value data.

    9. Click OK.
    10. On the Registry menu, click Exit.

    Now, when you save a Word document containing an EMF, PNG, GIF, or JPEG graphic in a different format (for example, Word 6.0/95 (*.doc) or Rich Text Format (*.rtf)), Word does not retain two copies of the graphic and does not dramatically increase the file size of the document as compared to the Word 2000 version of the file.

    C-c C-v from: experts.about.com/q/Microsoft-Word-1058/Word-97-inserting-jpg-3.htm

    First what you have to do is download odbc driver to PostgreSQL. You can find it on this site:
    ODBC driver . Instalation is very simple, just click next, next … After that you can configure your postgresql odbc connection go to:

    • menu
    • control panel
    • admin tools
    • sources data (ODBC)

    Open the last one, select user dsn tab, click add. Scroll down and find PostgreSQL driver name, select PostgreSQL Unicode, then click OK. After that you will see window perform field like below :

    • data source: PostgreSQL30W
    • database: your database name which you want connect
    • server: localhost (if it`s on this same machine)
    • user name: user name ;)
    • description: can be empty
    • SSL mode: disable (or choice what you need)
    • port: 5432
    • password: ****** (user pass)

    Then you can try test this setting by click test, if you will see „Connection succsessful” everything is ok now you can run dbdesigner;
    Go:
    -> file;
    -> open from databse;
    -> choice ODBC -> NewODBCConn
    -> click New Database connection.

    You will see window perform field like below:

    • connection name: whatever
    • driver: should be selected odbc if not select it
    • connection settings: don`t touch
    • odbc dsn name: PostgreSQL30W
    • username: user name ;)
    • password: ***** (user pass)

    Close this window and go to Database -> Reverse Engineering. You will see window called Select Database Connection, so select your connection and click Connect. On the next window you can select what you want import from db (choice it on Schema) after that just click „Execute”. And that`s all. After that you will see that what you selected on schema.

    On *nix, launching background processes is as simple as appending an ampersand (&) to the command. In Windows, it is not so simple to do from PHP.

    If you use the PHP exec or shell_exec commands to run a process, PHP will wait for the process to quit before continuing.

    This assumes that you are using PHP-CLI (from the command-line). Running PHP on a web server requires correct setup of configuration and permissions, such as safe_mode, safe_mode_exec_dir, etc.

    For example, suppose one wanted to launch cmd from PHP, and then continue executing. The following examples do not work.

    exec(”cmd”);
    exec(”cmd >NUL”);
    exec(”cmd /c cmd”);
    exec(”start /b cmd”);
    exec(”runas cmd”);

    In each case, PHP waits for cmd to quit before continuing.

    There are several workarounds mentioned in the comments of the PHP documentation of exec. Here is a summary of those methods, by order of preference.

    Start background process using the WScript.Shell object
    You can start the process using the Run method of the WScript.Shell object, which is built-in to Windows. By varying the second parameter, you can make the window hidden, visible, minimized, etc. By setting the third parameter to false, Run does not wait for the process to finish executing. This code only works on Windows.

    $WshShell = new COM(”WScript.Shell”);
    $oExec = $WshShell->Run(”cmd /C dir /S %windir%”, 0, false);

    Start background process using popen and pclose
    This code should work on Linux and Windows.
    pclose(popen(”start \”bla\” \”" . $exe . “\” ” . escapeshellarg($args), “r”));
    Start background process with psexec
    This method requires installing the freeware pstools from sysinternals:
    exec(”psexec -d blah.bat”);
    Start process without a window
    This is not really for background processes, but worth mentioning. Use the windows start command with /B switch to hide the window.
    exec(’start /B “window_name” “path to your exe”‘,$output,$return);