2015-06-19 69 views
-1

我最近开始将我的Intranet服务器升级到PHP,但我无法使代码正常工作。无法使用PHP?

<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" x-undefined> 
    </head> 
    <body> 
    <!-- php data test --> 
    <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0"> 
    <meta http-equiv="expires" content="Sat, 31 Oct 2014 00:00:00 GMT"> 
    <meta http-equiv="pragma" content="no-cache"> 
    </body> 
</html> 

<?php 
    // Connect to MSSQL and select the database 
    mssql_connect('intranet', 'sa', 'bobby123'); 
    mssql_select_db('phptable'); 

    // Send a select query to MSSQL 
    $query = mssql_query('SELECT * FROM [php].[dbo].[persons]'); 

    // Construct table 
    echo '<h3>Table structure for \'persons\'</h3>'; 
    echo '<table border="1">'; 

    // Table header 
    echo '<thead>'; 
    echo '<tr>'; 
    echo '<td>UserID</td>'; 
    echo '<td>Username</td>'; 
    echo '<td>Password</td>'; 
    echo '</tr>'; 
    echo '</thead>'; 

    // Dump all fields 
    echo '<tbody>'; 

    for ($i = 0; $i < mssql_num_fields($query); ++$i) { 
     // Fetch the field information 
     $field = mssql_fetch_field($query, $i); 

     // Print the row 
     echo '<tr>'; 
     echo '<td>' . $field->userid . '</td>'; 
     echo '<td>' . $field->username . '</td>'; 
     echo '<td>' . $field->password . '</td>'; 
     echo '</tr>'; 
    } 

    echo '</tbody>'; 
    echo '</table>'; 

    // Free the query result 
    mssql_free_result($query); 
?> 

我使用PHP 5.4,并还试图用5.5这是不是在我的代码,或者我需要安装一个插件或东西到我的服务器? (Windows Server 2012 R2)

+0

我建议你开始用一个简单的测试就像'的Hello World

”给出确切的表名;如果它能够工作,那么就去更复杂的测试。 – jcbermu

+0

简单的你好世界完美地显示页面? –

+0

完美(它不会让我编辑它...) –

回答

0

不需要任何额外的插件。 请勿删除代码中的异常。 如果它在那里,你可以简单地找到错误的位置。

变化语句等

mssql_connect( '内部网', '山', 'bobby123');

mssql_connect( '内部网', '山', 'bobby123')或死亡( '而连接到MSSQL出了点');

Intranet是一个国名吗?

+0

我使用“http:// intranet:999/index.php”(我的测试服务器)连接到Intranet。 '或死'也不起作用。 。 –

0

这可能是一些数据库连接问题。

获取确切的主机名,数据库名,用户名&密码和特定表名的名称。

使您的代码像下面

$connect = mssql_connect('hostname','username','password'); 
$db = mssql_select_db('database'); 

还请加mysql_error()功能来识别错误。 ?

在SQL语句而不是[php].[dbo].[persons]

+0

,没有任何改变。除了你需要添加一个;在mssql_error()的末尾,因为它是一个函数 –