Some advices for common programmers problems

Przy wykonywaniu skryptu PHP z lini poleceń Windows 7 zgłasza nieoczekiwany błąd aplikacji. O dziwo wygląda na to że polecenia są wykonywane, tylko wywala się moduł na zakończeniu.

Podobny problem jets opisany tutaj:
cli has stopped working on vista

W moim przypadku przyczyną nie był mysqli.dll tylko php_pop3.dll

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.

    This script simply parse given database (demo) and schema (reports) and make and execute desired queries.
    Output is saved id current dir.

    #!/bin/bash

    SCHEMA=reports
    DBNAME=demo

    psql -U postgres demo -t -c "\dt $SCHEMA. " > tables.dat
    psql -U postgres demo -t -c "\dv $SCHEMA. "> views.dat
    psql -U postgres demo -t -c "\ds $SCHEMA. " > sequence.dat

    echo "SET search_path TO $SCHEMA;" > sametables.sql
    echo "SET search_path TO $SCHEMA;" > sameviews.sql
    echo "SET search_path TO $SCHEMA;" > sameseq.sql

    cat tables.dat | awk -F'\|' '{print $2}' >> sametables.sql
    cat views.dat | awk -F'\|' '{print $2}' >> sameviews.sql
    cat sequence.dat | awk -F'\|' '{print $2}' >> sameseq.sql

    vim -c '%s/^\([ a-z0-9\-_]*\)$/GRANT select,insert,update,delete ON \1 TO http;/’ -c ‘wq’ sametables.sql
    vim -c ‘%s/^\([ a-z0-9\-_]*\)$/GRANT select ON \1 TO http;/’ -c ‘wq’ sameviews.sql
    vim -c ‘%s/^\([ a-z0-9\-_]*\)$/GRANT usage ON \1 TO http;/’ -c ‘wq’ sameseq.sql

    psql -U postgres $DBNAME -f sametables.sql
    psql -U postgres $DBNAME -f sameviews.sql
    psql -U postgres $DBNAME -f sameseq.sql

    psql -U postgres $DBNAME -c “grant ALL ON schema $SCHEMA TO http;”