ODBC linux PHP Syntax error?

A

Anonymous

Guest
Hi,
I was wondering if someone could lend me a hand on the issue im having. We currently have an internal web for our users. The website was created by another person using PHP and that person we cannot reach them. The website was hosted using XAMPP on a windows server using ODBC to connect to a windows sql server for that database.

Currently I migrated the htdocs to a ubuntu Server 14.04 running NGINX with php5. I also installed FreeTDS and successfully connected to the sql server using ODBC. When i go to website the front page work, but when i put in the username and password i get a HTTP 500 error . After checking the error log on NGINX

Code:
  2017/11/14 17:50:09 [error] 7482#0: *42 FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected '}' in /var/www/html/xampp/htdocs/index2.php on line 47" while reading response header from upstream, client: 192.168.40.38, server: 192.168.1.3, request: "POST /index2.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "192.168.1.3", referrer: "http://192.168.1.3/"



after looking at a while the index2.php file is this

https://pastebin.com/ABmWvsc2

and after looking at it i saw a "require_once" which leads to the barras.php

https://pastebin.com/PKfcaxe9

Now the question is how come its giving a syntax error if the website was working before on XAMPP am i missing a php package?

These are the packages of php i installed

Code:
 apt-get install php5 php5-mysql php5-mcrypt php5-gd php5-fpm
Code:
apt-get install php5-odbc

Thank you

https://imgur.com/a/5CJQn----Working connect to ms sql
 
You have a syntax error in your index2.php file.

I don't look at external links, however, there is a closing } in your file on line 47 which does not have an opening one.

The errors were probably suppressed in the old set up, what you will need to do is figure out why the bracket is there and see if something is missing or if you can just delete it. Don't assume that you can just delete it though as there may be something else going on.

Feel free to post your code on here, if you can't find the problem, using the </> code button in the reply box; bear in mind that this is a help forum for people learning php.
 
Thanks for the reply the i changed a bit the index2.php which is this

Code:
<html>
<head>
    <title>Intranet</title>
</head>
<?php
require_once('barras.php');
$seguir=true;
 
if (isset($B1))
{
    if ($B1=="Entrar")
    {
        $rs= odbc_exec($conexion,"select nombre,nivel,seccion,cargo from tblpersonal where usuario='$usuario' and clave='$clave'");
        if (odbc_fetch_row($rs))
        {
 
            $nivel=odbc_result($rs,"nivel");
            $nombre=odbc_result($rs,"nombre");
            $seccion=odbc_result($rs,"seccion");
            $cargo=odbc_result($rs,"cargo");
 
            $_SESSION["nivel"] = $nivel;
            $_SESSION["usuario"] = $usuario;
            $_SESSION["nombre"] = $nombre;
            $_SESSION['seccion'] = $seccion;
            $_SESSION['cargof'] = $cargo;
            echo "<frameset framespacing=\"0\" border=\"1\" frameborder=\"1\" rows=\"90,*\">
               <frame name=\"superiord\" target=\"izquierdo\" src=\"menusup.htm\" scrolling=\"auto\" >
               <frameset framespacing=\"0\" border=\"1\" frameborder=\"1\" cols=\"220,*\">
                   <frame name=\"izquierdo\" scrolling=\"auto\" noresize target=\"principal\" src=\"inicial.htm\">
                   <frame name=\"principal\" src=\"titulo.htm\" marginwidth=\"1\" marginheight=\"1\" scrolling=\"auto\">
               </frameset>
               <noframes>
                   <body>
                       <p>Esta página usa marcos, pero su explorador no los admite.</p>
                   </body>
               </noframes>
           </frameset>";
        }
        else
        {
            echo "<body link=\"#FFFFFF\" alink=\"#FFFFFF\" text=\"#FFFFFF\" bgcolor=\"#003366\" style=\"font-family: Arial\">
           <p><center><h2>Clave Incorrecta</center></h2></p>
           </body>";
        }
    }
    else
    {
        //$nivel=$_SESSION['nivel'];
    }
}
else
{
    echo "<body link=\"#FFFFFF\" alink=\"#FFFFFF\" text=\"#FFFFFF\" bgcolor=\"#003366\" style=\"font-family: Arial\">
   <p><center><h2>Debe realizar la Autenticación de Seguridad</center></h2></p>
   </body>";
}
?>
</html>

that part is fixed but now im getting an issue with the ODBC connect :( this is the error

Code:
 2017/11/15 18:48:03 [error] 835#0: *54 FastCGI sent in stderr: "PHP message: PHP Warning:  odbc_connect(): SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /var/www/html/xampp/htdocs/barras.php on line 9" while reading response header from upstream, client: 192.168.40.38, server: 192.168.1.3, request: "POST /index2.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "192.168.1.3", referrer: "http://192.168.1.3/"

But not sure why, as these are my config of the odbc:

barras.php
Code:
   <?php
  # FileName="Connection_php_mysql.htm"
  # Type="MSSQL"
 # HTTP="true"
 $hostname_barras = "OPTIMUS1";
 $database_barras = "db";
 $username_barras = "intranet";
 $password_barras = "mypassword";
$connection = odbc_connect("MSSQL","intranet","mypassword");
?>

odbcinst.ini
Code:
[FreeTDS]
 Description = FreeTDS driver
 Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
 Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
 CPTimeout = 5
 CPReuse = 5
  FileUsage = 1

odbc.ini
Code:
 [MSSQL]
Description = MS SQL Server
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Servername = 192.168.1.152
Username = intranet
Password = mypassword
Database = db
 Port = 1433
Trace = No

[Default]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

Thank you again
 
Thanks for the reply, as the index2.php on the code it does a redirect to the barras.php which gets the info of the ODBC
on the NGINX server i point the root directory to the htdocs

Thank you
 
Thanks for the reply, when you mean database do you mean the odbc.ini? or the barras.php?
 
Ok, you are telling PHP to connect to your database here:
/var/www/html/xampp/htdocs/
PHP is saying, it isn't there; either you haven't put the database on your system, or you have put is somewhere else that php is unaware of.
 
thanks for the reply, as the database is in Microsoft SQL in another server 192.168.1.152 im using ODBC trying to connect it.
 
Back
Top