Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2008
    Posts
    4

    Question Unanswered: Pervasive 7 and PHP 4.X

    Hi people.

    I have 1 server running Pervasive 7.x in a Linux box, i can connect over windows clients using the ODBC stuff, but now i want to jump some applications to the web using PHP 4.x.

    The linux box is running Centos 4.6 + apache 2.0 + PHP 4.X, want i want is to use any standard browser(Firefox or IExplore) to connect my clients to my server, my clients can be windows xp or Linux Centos, Ubuntu or Fedora.

    I already load UnixODBC + php-odbc, but what really don't understand is what i need to setup in my server to connect PHP with Pervasive

    I have seen on other posts some examples, but went i run this script send errors:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>PHP Sample</TITLE>
    </HEAD>
    <BODY>
    <?php
    $conn=odbc_connect("Demodata","","","");
    $sql="select * from class";
    $rs=odbc_exec($conn,$sql);
    echo "<table border=1>\n";
    $numfields = odbc_num_fields($rs);
    for($i=1;$i<=$numfields;$i++){
    $fn=odbc_field_name($rs,$i);
    echo "<th>$fn</th>";
    }
    echo "\n";
    while(odbc_fetch_row($rs)){
    echo "<tr>\n";
    for($i=1;$i<=$numfields;$i++){
    $fv=odbc_result($rs,$i);
    echo "<td>$fv</td>";
    }
    echo "</tr>\n";
    }
    echo "</table>\n";
    echo "<p>Number of Fields: $numfields</p>\n";
    ?>
    </BODY>
    </HTML>

    PHP Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/html/odbc.php on line 8
    PHP Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /var/www/html/odbc.php on line 10
    <table border=1>
    PHP Warning: odbc_num_fields(): supplied argument is not a valid ODBC result resource in /var/www/html/odbc.php on line 12

    PHP Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in /var/www/html/odbc.php on line 18

    I have read a lot of this here in this site, but i still don't answer my question, hope some could point me something, i will aprecciated, thanks all for your time

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You error all stems from the DSN name you have provided (Demodata). Because your linux machine doesn't have this DSN (because it's linux) you need to supply the full ODBC connection string there instead.

    Something like:
    odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbq",$username, $password);

    But obviously for pervasive instead... It also may require the Pervasive driver being installed into odbc.

  3. #3
    Join Date
    Mar 2008
    Posts
    4

    Question

    Hi aschk.

    I already setup the ODBC.ini that is inside /etc, pervasive use his own paths and install the odbc.ini in /usr/local/psql/etc, i just update the /etc/odbc.ini with pervisive info, and add the pervasive library to Linux library paths and i could run the script from the shell.

    I test odbc tools to test connection and they where good.
    I run the script from the shell and success.

    The only problem right now is that if i run the script from the browser still tell me that cannot connect to the DB, i still don't get a clue about

    What this could happen

    Thanks aschk for your tip

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    ODBC doesn't know about pervasive, i.e. couldn't load the correct driver.
    Hence your error:
    [unixODBC][Driver Manager]Data source name not found, and no default driver specified
    PHP odbc needs to know about pervasive.

  5. #5
    Join Date
    Mar 2008
    Posts
    4

    Question

    Hi.

    I have been working with this small problem aschk, but i still don't or maybe don't understand your answer.

    Look, with isql i can access my pervasive:

    [root@server1 ~]# isql -v DEMODATA
    +---------------------------------------+
    | Connected! |
    | |
    | sql-statement |
    | help [tablename] |
    | quit |
    | |
    +---------------------------------------+

    SQL> select * from class where id=4
    +------------+--------+--------+---------+-----------+-----------+------------+--------------------------+------------+-----------------------+
    | ID | Name | Section| Max_Size| Start_Date| Start_Time| Finish_Time| Building_Name | Room_Number| Faculty_ID |
    +------------+--------+--------+---------+-----------+-----------+------------+--------------------------+------------+-----------------------+
    | 4 | ACC 102| 001 | 30 | 1995-06-05| 14:00:00 | 16:50:00 | Bhargava Building | 102 | 325173078 |
    +------------+--------+--------+---------+-----------+-----------+------------+--------------------------+------------+-----------------------+
    SQLRowCount returns -1
    1 rows fetched

    Here everything is working as u can see.

    Now if i run the same script from the shell, i can access the databases:

    [root@server1 html]# php odbc2.php
    Content-type: text/html
    X-Powered-By: PHP/4.3.9

    CTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>PHP Sample</TITLE>
    </HEAD>
    <BODY>
    <table border=1>
    <th>ID</th><th>Name</th><th>Section</th><th>Max_Size</th><th>Start_Date</th><th>Start_Time</th><th>Finish_Time</th><th>Building_Name</th><th>Room_Number</th><th>Faculty_ID</th>
    <tr>
    <td>4</td><td>ACC 102</td><td>001</td><td>30</td><td>1995-06-05</td><td>14:00:00</td><td>16:50:00</td><td>Bhargava Building </td><td>102</td><td>325173078</td></tr>
    </table>
    <p>Number of Fields: 10</p>
    </BODY>
    </HTML>

    I change the query just to return me 1 row and success.

    But what happen if i run the script from the browser:

    CTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    Warning: odbc_connect(): SQL error: [unixODBC][Pervasive][ODBC Engine Interface][Data Record Manager]The MicroKernel or Btrieve Requester is inactive(Btrieve Error 20), SQL state S1000 in SQLConnect in /var/www/html/odbc2.php on line 9

    Could not connect to databases

    My Pervasive is running, if not my isql command wouldn't success, example:

    root@server1 isql -v demodata
    [S1000][unixODBC][Pervasive][ODBC Engine Interface][Data Record Manager]The MicroKernel or Btrieve Requester is inactive(Btrieve Error 20)
    [ISQL]ERROR: Could not SQLConnect

    Now, what else maybe is missing or i forget to setup

    Thanks for your support

  6. #6
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Check http://www.pervasive.com/documentati...plications.pdf , page 13. Basically you need to provide an ODBC DSN String, which you aren't doing currently. You're providing "DemoData", but the DSN DemoData DOESN'T exist, hence your error. You need to provide something like
    "Driver={Pervasive ODBC Engine Interface};DBQ=DemoData"

    If you continue to get Driver engine errors, then you HAVEN'T compiled PHP with ODBC and the Pervasive ODBC driver, which I suspect is the actual problem (and i've reiterated several times now ), you should be able to use phpinfo() to find out whether ODBC has the pervasive driver installed.

  7. #7
    Join Date
    Mar 2008
    Posts
    4

    Thumbs up

    Hi aschk.

    After some analysis i found the problem and already fix the problem between PHP + Pervasive, the key was to add apache user to pervasive group. Pervasive install the user psql and group pvsw.

    All the databases run with this user and group, it doesn't have that user rights like others DB, them after i did this change my script succeed...

    I already test with Centos 5.x and have this small manual:
    1; Install Samba + Pervasive + Apache + PHP + PHP-odbc
    2; Add pervasive lib(/usr/local/psql/lib) to system lib paths

    echo "/usr/local/psql/lib" >> /etc/ld.so.conf
    run ldconfig

    3; Add pervasive /usr/local/psql/etc/odbc.ini data to /etc/odbc.ini,
    backup pervasive odbc.ini and create symlink from /etc/odbc.ini to /usr/local/psql/etc

    cp /usr/local/psql/etc/odbc.ini /usr/local/psql/etc/odbc.ini.backup
    rm -f /usr/local/psql/etc/odbc.ini
    ln -s /etc/odbc.ini /usr/local/psql/etc/

    4; Customize samba + php, and run samba service
    5; add user apache to pervasive group
    6; run apache +pervasive services
    7 ; Test your script from shell, test unixodbc(isql) and finally test the script from your browser

    Now we are on track again, aschk thanks for your great help, u give me new ways to search, thanks, now lets continue with the show, see u

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •