Jump to content

PHP on new server no longer connects (MSSQL)


Moron

Recommended Posts

We're moving to a new web server and we recently migrated to a new MS SQL server, as well. All PHP functions on the old web server were switched to point to the new SQL server and all was well.

 

But..... Now I''m trying to move my PHP functions to the new web server and it won't connect to the database. PHP works fine because I can echo "Testing" or whatever. I've downloaded the SQL Server PHP drivers from Microsoft, changed the connection string from MSSQL to SQLSRV, updated the PHP.ini file, and taken several other steps. It still can't see the database.

 

Ideas?

 

Oh, yeah. And both the new web server and MS SQL server are Server 2008 R2.

 

Link to comment
Share on other sites

What do you mean by "can't see"? Can't get to the database machine itself? Can't authenticate? Can't get to the database?

 

It pulls no data. I have a "die" statement and it shows nothing. The exact same file ran from the old web server pulls data galore.

 

Link to comment
Share on other sites

Are you sure that it's not showing any data versus PHP crashing and dying? I would bet there's a different problem from the databasework; maybe syntax (are the PHP versions on the old machine and the new machine the same?) maybe settings (how about the php.ini settings?), or maybe something else.

 

As you should to for a development machine, make sure your new web server's php.ini has

error_reporting = -1
display_errors = on

then restart the web server software (ie, Apache or IIS), run your script(s) again, and look for error messages.

Link to comment
Share on other sites

Are you sure that it's not showing any data versus PHP crashing and dying? I would bet there's a different problem from the databasework; maybe syntax (are the PHP versions on the old machine and the new machine the same?) maybe settings (how about the php.ini settings?), or maybe something else.

 

As you should to for a development machine, make sure your new web server's php.ini has

error_reporting = -1
display_errors = on

then restart the web server software (ie, Apache or IIS), run your script(s) again, and look for error messages.

 

Thanks. I made both changes, saved the file, then stopped and restarted the website in IIS. Same result.

 

 

Link to comment
Share on other sites

Do a phpinfo() to make sure the new settings took effect.

 

If View Source doesn't show anything then your code never outputs anything.

 

I did, and it made the "-mssql" and "-sqldrv" go away, so I'm thinking that they successfully loaded.

 

Link to comment
Share on other sites

If View Source doesn't show anything then your code never outputs anything.

 

I did this, and WOW. View Source shows me the entire PHP page, including the connection statement with user name and password.

 

So what does this mean?

 

Link to comment
Share on other sites

Sounds like your PHP file is not being run.  You have not installed/activated PHP correctly.

 

 

But if I go:

 

<? php
echo "Testing";
?>

 

...it will echo it fine. The browser doesn't display the PHP code; it's only when I View Source. We also have other things running in PHP on this server.

 

Link to comment
Share on other sites

You are probably using short open tags <? in some of your files.

 

You should ONLY use full opening <?php tags so that your php code will always be seen as being php code, regardless of which server it is being run on.

 

Nope. It's all long tags.

 

Here's the code:

 

<?php

$msconnect=sqlsrv_connect('SERVERNAME','username','password') or die ("Could not connect to database: ".sqlsrv_get_last_message());;
$msdb=sqlsrv_select_db("TableName",$msconnect) or die ("Could not connect to table: ".sqlsrv_get_last_message());;

?>

<?php


if($_POST['THOUSE'] || $_POST['TNSEW'] || $_POST['TSTNAM']) {
$where = " WHERE	(THOUSE LIKE '%{$_POST['THOUSE']}%' AND TNSEW LIKE '%{$_POST['TNSEW']}%' AND TSTNAM LIKE '%{$_POST['TSTNAM']}%')";
$order = " ORDER BY THOUSE, TNSEW, TSTNAM";
} elseif ($_POST['TRECTN']) {
if (!$_POST['TTAXYRa']) { $_POST['TTAXYRa'] = date("Y"); }
$where = " WHERE	(TRECTN = '{$_POST['TRECTN']}' AND TTAXYR = '{$_POST['TTAXYRa']}')";
$order = " ORDER BY TRECTN";
} elseif($_POST['TNAME1']) {
$where = " WHERE	(TNAME1 LIKE '%{$_POST['TNAME1']}%')";
$order = " ORDER BY TNAME1, TNAME2";
} elseif($_POST['TMAPN'] || $_POST['TMAPA'] || $_POST['TPARCL'] || $_POST['TGROUP'] || $_POST['TPICOD'] || $_POST['TSPCIN']) {
$where = " WHERE	(TMAPN LIKE '%{$_POST['TMAPN']}%' AND TMAPA LIKE '%{$_POST['TMAPA']}%' AND TPARCL LIKE '%{$_POST['TPARCL']}%' AND TGROUP LIKE '%{$_POST['TGROUP']}%' AND TPICOD LIKE '%{$_POST['TPICOD']}%' AND TSPCIN LIKE '%{$_POST['TSPCIN']}%')";
$order = " ORDER BY TMAPN,TMAPA,TPARCL";

} else {
header("location: TestSearch.php");
}

if ($_POST['TTAXYR'] && !$_POST['TTAXYRa']) {
$where .= " AND (TTAXYR = ".date("Y").")";
}
$order .= ", TTAXYR DESC";

$query = "SELECT TRECTN,TTAXYR, TNAME1, TSTADR, TTXAMT, TTXBAL, THOUSE, TNSEW, TSTNAM
				FROM viewTAXINFO_FULL
				$where
				$order";

$result = @sqlsrv_query($query);

if (@sqlsrv_num_rows($result) == 1) {
$row = @sqlsrv_fetch_assoc($result);
header("location: TestView.php?TRECTN={$row['TRECTN']}&TTAXYR={$row['TTAXYR']}");
exit;
}

?>
<html>
<head>
<title>CITY OF OAK RIDGE PROPERTY TAX SEARCH RESULTS</title>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
h1
{margin:0in;
margin-bottom:.0001pt;
page-break-after:avoid;
font-size:12.0pt;
font-family:"Times New Roman";}
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Verdana;
color:black;}
p.bodytext, li.bodytext, div.bodytext
{margin-right:0in;
margin-left:0in;
font-size:10.0pt;
font-family:Verdana;
color:black;}
@page Section1
{size:8.5in 11.0in;
margin:.2in .2in .2in .2in;}
div.Section1
{page:Section1;}
table {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
-->
</style>
<link rel=Original-File href=TestSearch.php>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<center>
<body lang=EN-US topmargin="5" leftmargin="3">
<div class=Section1>

        <table width="480" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td width="230" bgcolor="#006633"><span class="style1"><center>Owner</center></span></td>
            <td width="190" bgcolor="#006633"><span class="style1"><center>Address</center></span></td>
            <td width="10" bgcolor="#006633"><span class="style1"><center>Tax Year </center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Tax Amount</center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Balance </center></span></td>
	<td width="25" bgcolor="#006633"><span class="style1"><center>Receipt </center></span></td>
          </tr>
          <?php if (@sqlsrv_num_rows($result) > 0) { ?>
	  <?php while($row = @sqlsrv_fetch_assoc($result)) { ?>
          <tr>
            <td bgcolor="#E2E2E2"><a href="TestView.php?TRECTN=<?php= $row['TRECTN']; ?>&TTAXYR=<?php= $row['TTAXYR']; ?>">
              <?php= $row['TNAME1']; ?>
              </a> </td>
            <td bgcolor="#E2E2E2">
              <?php= $row['THOUSE']; ?> <?php= $row['TNSEW']; ?>  <?php= $row['TSTNAM']; ?></td>
            <td bgcolor="#E2E2E2">
              <div align="center">
                <?php= $row['TTAXYR']; ?></div></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXAMT'],2); ?></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXBAL'],2); ?></td>
	<td align="right" bgcolor="#E2E2E2"><?php= ($row['TRECTN']); ?></td>
          </tr>
	  <?php } ?>
	  <?php } else { ?>
	  <tr><td colspan="5">Search yielded no results.</td></tr>
	  <?php } ?>
</table>

</center>
</body>
</html>

 

And again, this same code (modified here to remove private info) runs against the same SQL server just fine from another web server.

 

I'm stumped.

 

Link to comment
Share on other sites

Is this code (that you see the raw php code in the 'view source' in your browser) in the same folder where you have tried php code that does work?

 

 

 

 

EDIT: I think I misunderstood you. Sorry about that.

 

On the same file that shows me nothing, I can echo things and they display properly.

 

Link to comment
Share on other sites

Ok I have checked your code and would like you to use the following amended code.

 

I have removed the @  suppressors.  This will show any errors that may have been suppressed.  If you get any errors post them back here.

 

<?php

$msconnect=sqlsrv_connect('SERVERNAME','username','password') or die ("Could not connect to database: ".sqlsrv_get_last_message());;
$msdb=sqlsrv_select_db("TableName",$msconnect) or die ("Could not connect to table: ".sqlsrv_get_last_message());;

?>

<?php


if($_POST['THOUSE'] || $_POST['TNSEW'] || $_POST['TSTNAM']) {
$where = " WHERE	(THOUSE LIKE '%{$_POST['THOUSE']}%' AND TNSEW LIKE '%{$_POST['TNSEW']}%' AND TSTNAM LIKE '%{$_POST['TSTNAM']}%')";
$order = " ORDER BY THOUSE, TNSEW, TSTNAM";
} elseif ($_POST['TRECTN']) {
if (!$_POST['TTAXYRa']) { $_POST['TTAXYRa'] = date("Y"); }
$where = " WHERE	(TRECTN = '{$_POST['TRECTN']}' AND TTAXYR = '{$_POST['TTAXYRa']}')";
$order = " ORDER BY TRECTN";
} elseif($_POST['TNAME1']) {
$where = " WHERE	(TNAME1 LIKE '%{$_POST['TNAME1']}%')";
$order = " ORDER BY TNAME1, TNAME2";
} elseif($_POST['TMAPN'] || $_POST['TMAPA'] || $_POST['TPARCL'] || $_POST['TGROUP'] || $_POST['TPICOD'] || $_POST['TSPCIN']) {
$where = " WHERE	(TMAPN LIKE '%{$_POST['TMAPN']}%' AND TMAPA LIKE '%{$_POST['TMAPA']}%' AND TPARCL LIKE '%{$_POST['TPARCL']}%' AND TGROUP LIKE '%{$_POST['TGROUP']}%' AND TPICOD LIKE '%{$_POST['TPICOD']}%' AND TSPCIN LIKE '%{$_POST['TSPCIN']}%')";
$order = " ORDER BY TMAPN,TMAPA,TPARCL";

} else {
header("location: TestSearch.php");
}

if ($_POST['TTAXYR'] && !$_POST['TTAXYRa']) {
$where .= " AND (TTAXYR = ".date("Y").")";
}
$order .= ", TTAXYR DESC";

$query = "SELECT TRECTN,TTAXYR, TNAME1, TSTADR, TTXAMT, TTXBAL, THOUSE, TNSEW, TSTNAM
				FROM viewTAXINFO_FULL
				$where
				$order";

$result = @sqlsrv_query($query);

if (@sqlsrv_num_rows($result) == 1) {
$row = sqlsrv_fetch_assoc($result);
header("location: TestView.php?TRECTN={$row['TRECTN']}&TTAXYR={$row['TTAXYR']}");
exit;
}

?>
<html>
<head>
<title>CITY OF OAK RIDGE PROPERTY TAX SEARCH RESULTS</title>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
h1
{margin:0in;
margin-bottom:.0001pt;
page-break-after:avoid;
font-size:12.0pt;
font-family:"Times New Roman";}
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Verdana;
color:black;}
p.bodytext, li.bodytext, div.bodytext
{margin-right:0in;
margin-left:0in;
font-size:10.0pt;
font-family:Verdana;
color:black;}
@page Section1
{size:8.5in 11.0in;
margin:.2in .2in .2in .2in;}
div.Section1
{page:Section1;}
table {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
-->
</style>
<link rel=Original-File href=TestSearch.php>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<center>
<body lang=EN-US topmargin="5" leftmargin="3">
<div class=Section1>

        <table width="480" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td width="230" bgcolor="#006633"><span class="style1"><center>Owner</center></span></td>
            <td width="190" bgcolor="#006633"><span class="style1"><center>Address</center></span></td>
            <td width="10" bgcolor="#006633"><span class="style1"><center>Tax Year </center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Tax Amount</center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Balance </center></span></td>
	<td width="25" bgcolor="#006633"><span class="style1"><center>Receipt </center></span></td>
          </tr>
          <?php if (sqlsrv_num_rows($result) > 0) { ?>
	  <?php while($row = sqlsrv_fetch_assoc($result)) { ?>
          <tr>
            <td bgcolor="#E2E2E2"><a href="TestView.php?TRECTN=<?php= $row['TRECTN']; ?>&TTAXYR=<?php= $row['TTAXYR']; ?>">
              <?php= $row['TNAME1']; ?>
              </a> </td>
            <td bgcolor="#E2E2E2">
              <?php= $row['THOUSE']; ?> <?php= $row['TNSEW']; ?>  <?php= $row['TSTNAM']; ?></td>
            <td bgcolor="#E2E2E2">
              <div align="center">
                <?php= $row['TTAXYR']; ?></div></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXAMT'],2); ?></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXBAL'],2); ?></td>
	<td align="right" bgcolor="#E2E2E2"><?php= ($row['TRECTN']); ?></td>
          </tr>
	  <?php } ?>
	  <?php } else { ?>
	  <tr><td colspan="5">Search yielded no results.</td></tr>
	  <?php } ?>
</table>

</center>
</body>
</html>

Link to comment
Share on other sites

Ok I have checked your code and would like you to use the following amended code.

 

I have removed the @  suppressors.  This will show any errors that may have been suppressed.  If you get any errors post them back here.

 

<?php

$msconnect=sqlsrv_connect('SERVERNAME','username','password') or die ("Could not connect to database: ".sqlsrv_get_last_message());;
$msdb=sqlsrv_select_db("TableName",$msconnect) or die ("Could not connect to table: ".sqlsrv_get_last_message());;

?>

<?php


if($_POST['THOUSE'] || $_POST['TNSEW'] || $_POST['TSTNAM']) {
$where = " WHERE	(THOUSE LIKE '%{$_POST['THOUSE']}%' AND TNSEW LIKE '%{$_POST['TNSEW']}%' AND TSTNAM LIKE '%{$_POST['TSTNAM']}%')";
$order = " ORDER BY THOUSE, TNSEW, TSTNAM";
} elseif ($_POST['TRECTN']) {
if (!$_POST['TTAXYRa']) { $_POST['TTAXYRa'] = date("Y"); }
$where = " WHERE	(TRECTN = '{$_POST['TRECTN']}' AND TTAXYR = '{$_POST['TTAXYRa']}')";
$order = " ORDER BY TRECTN";
} elseif($_POST['TNAME1']) {
$where = " WHERE	(TNAME1 LIKE '%{$_POST['TNAME1']}%')";
$order = " ORDER BY TNAME1, TNAME2";
} elseif($_POST['TMAPN'] || $_POST['TMAPA'] || $_POST['TPARCL'] || $_POST['TGROUP'] || $_POST['TPICOD'] || $_POST['TSPCIN']) {
$where = " WHERE	(TMAPN LIKE '%{$_POST['TMAPN']}%' AND TMAPA LIKE '%{$_POST['TMAPA']}%' AND TPARCL LIKE '%{$_POST['TPARCL']}%' AND TGROUP LIKE '%{$_POST['TGROUP']}%' AND TPICOD LIKE '%{$_POST['TPICOD']}%' AND TSPCIN LIKE '%{$_POST['TSPCIN']}%')";
$order = " ORDER BY TMAPN,TMAPA,TPARCL";

} else {
header("location: TestSearch.php");
}

if ($_POST['TTAXYR'] && !$_POST['TTAXYRa']) {
$where .= " AND (TTAXYR = ".date("Y").")";
}
$order .= ", TTAXYR DESC";

$query = "SELECT TRECTN,TTAXYR, TNAME1, TSTADR, TTXAMT, TTXBAL, THOUSE, TNSEW, TSTNAM
				FROM viewTAXINFO_FULL
				$where
				$order";

$result = @sqlsrv_query($query);

if (@sqlsrv_num_rows($result) == 1) {
$row = sqlsrv_fetch_assoc($result);
header("location: TestView.php?TRECTN={$row['TRECTN']}&TTAXYR={$row['TTAXYR']}");
exit;
}

?>
<html>
<head>
<title>CITY OF OAK RIDGE PROPERTY TAX SEARCH RESULTS</title>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
h1
{margin:0in;
margin-bottom:.0001pt;
page-break-after:avoid;
font-size:12.0pt;
font-family:"Times New Roman";}
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Verdana;
color:black;}
p.bodytext, li.bodytext, div.bodytext
{margin-right:0in;
margin-left:0in;
font-size:10.0pt;
font-family:Verdana;
color:black;}
@page Section1
{size:8.5in 11.0in;
margin:.2in .2in .2in .2in;}
div.Section1
{page:Section1;}
table {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
-->
</style>
<link rel=Original-File href=TestSearch.php>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<center>
<body lang=EN-US topmargin="5" leftmargin="3">
<div class=Section1>

        <table width="480" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td width="230" bgcolor="#006633"><span class="style1"><center>Owner</center></span></td>
            <td width="190" bgcolor="#006633"><span class="style1"><center>Address</center></span></td>
            <td width="10" bgcolor="#006633"><span class="style1"><center>Tax Year </center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Tax Amount</center></span></td>
            <td width="25" bgcolor="#006633"><span class="style1"><center>Balance </center></span></td>
	<td width="25" bgcolor="#006633"><span class="style1"><center>Receipt </center></span></td>
          </tr>
          <?php if (sqlsrv_num_rows($result) > 0) { ?>
	  <?php while($row = sqlsrv_fetch_assoc($result)) { ?>
          <tr>
            <td bgcolor="#E2E2E2"><a href="TestView.php?TRECTN=<?php= $row['TRECTN']; ?>&TTAXYR=<?php= $row['TTAXYR']; ?>">
              <?php= $row['TNAME1']; ?>
              </a> </td>
            <td bgcolor="#E2E2E2">
              <?php= $row['THOUSE']; ?> <?php= $row['TNSEW']; ?>  <?php= $row['TSTNAM']; ?></td>
            <td bgcolor="#E2E2E2">
              <div align="center">
                <?php= $row['TTAXYR']; ?></div></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXAMT'],2); ?></td>
            <td align="right" bgcolor="#E2E2E2">$<?php= number_format($row['TTXBAL'],2); ?></td>
	<td align="right" bgcolor="#E2E2E2"><?php= ($row['TRECTN']); ?></td>
          </tr>
	  <?php } ?>
	  <?php } else { ?>
	  <tr><td colspan="5">Search yielded no results.</td></tr>
	  <?php } ?>
</table>

</center>
</body>
</html>

 

Thanks, but.......it still comes up totally blank.

 

Link to comment
Share on other sites

Ummm. That code still has several @ error suppressors in front of php statements. Until you remove all of the @'s in the php code, you won't get accurate reporting of errors that would help you determine what is happening.

 

In the phpinfo() output, what values are shown for the error_reporting and display_errors settings?

 

Don't ever use @'s in your php code to suppress errors, they are not need. On a development system (or when debugging your code), you would have php's display_errors set to ON. On a live site, you would have php's display_errors set to OFF and log_errors set to ON.

 

Going back to some previous information in this thread. Did you or did you not do a 'view source' of a blank page in your browser and see the raw php code? Also, a question I asked that wasn't really answered - are all these php files (the one with posted code, the ones that work, the one with the phpinfo() statement in it) in the same folder or are they in different paths/folders (i.e. do php files at one path, say the document root, work and php files in a folder don't work and show the raw php code in the 'view source' of the page in your browser)?

 

Are you accessing this 'new' web server locally (i.e. where is it located vs where your client computer is located)?

Link to comment
Share on other sites

I just looked at the code on your page closer and you have a number of statements like this <?php=

 

You did have some <?= short tags/print statements in your (working) code and you blindly did a search and replace to change <? into <?php didn't you? Now you either need to go back to your working original source code or you need to go though all your current code and change the <?php= to <?php echo

Link to comment
Share on other sites

Thanks, everyone, and sorry about my delayed response. What a day.

 

Okay, from the top.....

 

I went back and removed all of the suppressors (@) from the code.

 

PFM, you are correct. I did exactly that, searched and replaced "<?" with "<?php." I'll go back in and fix that.

 

For some reason, it no longer displays the php code when I right-click and View Source. I don;t know what "fixed" that.

 

And again, I appreciate everyone's suggestions.

 

 

Link to comment
Share on other sites

Okay, I have an update and it gets weirder by the minute. I replaced the "<?" tags with "<?php." All fine and good.

 

Except......I can't do this on the very first tag. If I use the short tag, I get this:

 

phpblank.jpg

 

I know the data is there (and plenty of it), yet it shows me nothing. If I use the long tag, only on this first tag at the top, I get a blank page.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.