0

マシン上の MySQL データベースにアクセスしようとしています。ポート1338にあります。

これは PHP ファイルです。

<!DOCTYPE html>

<html>

<head>

</head>


<body>

    <table>
    <?php

        $connection = mysql_connect("localhost:1338","root","password"); //connects to db
        $selected = mysql_select_db("site_updatelog"); //selects the db to be used
        //Check whether connection was successful
        if(!$connection){
            die('Could not connect to database: ' . mysql_error()); //Stop further execution of php script and show the error that occured
        }

        $sql = "SELECT comments, version, datetime FROM changeLog ORDER BY id DESC"; //form the query to be executed on the db
        $result = mysql_query($sql, $connections) or die (mysql_error()); //execute the query, or die if there was an error

        while($row = mysql_fetch_array($result)){
            //Display the table of results
            echo "<tr><td>". $row['version'] ."</td><td>". $row['comments'] ."</td><td>". $row['datetime'] ."</td></tr>";
        }

        mysql_close($connection);
     ?>
</table>


</body>

</html>

これは出力です:

"; } mysql_close($connection); ?>
". $row['version'] ."   ". $row['comments'] ."  ". $row['datetime'] ."

かなり長い間いじっていますが、まだ機能しません。何か案は?

4

3 に答える 3

1

mysql_query($sql, $connections)で変わるmysql_query($sql, $connection)

于 2012-11-24T14:49:26.073 に答える
1

おそらく、エコーしているデータにエスケープされていない文字があるためです-$row['comments']、$row['version']、および$row['datetime']をhtmlspecialscharsにラップしてみてください

于 2012-11-24T15:15:59.667 に答える
0

以下のコードを使用すると、次の場合にのみ死亡し、エラーが報告されます(!$connection)

$connection = mysql_connect("localhost:1338","root","password"); //connects to db
        $selected = mysql_select_db("site_updatelog"); //selects the db to be used
        //Check whether connection was successful
        if(!$connection){
            die('Could not connect to database: ' . mysql_error()); //Stop further execution of php script and show the error that occured
        }

使ってみて

$connection = mysql_connect("localhost:1338","root","password"); //connects to db
        //Check whether connection was successful
        if(!$connection){
            die('Could not connect to database: ' . mysql_error()); //Stop further execution of php script and show the error that occured
        }
        $selected = mysql_select_db("site_updatelog",$connection); //selects the db to be used
        if (!$db_selected) {
            die ("Can\'t use db : " . mysql_error());
        }
        $sql = "SELECT comments, version, datetime FROM changeLog ORDER BY id DESC"; //form the query to be executed on the db
        $result = mysql_query($sql) ;

        while($row = mysql_fetch_assoc($result)){
            //Display the table of results
            echo "<tr><td>". $row['version'] ."</td><td>". $row['comments'] ."</td><td>". $row['datetime'] ."</td></tr>";
        }

        mysql_close($connection);

これにより、クエリを実行する前にエラーがスローされます。また、必要に応じて2つのパラメーターに変更されましmysql_fetch_array()mysql_fetch_assoc()mysql_fetch_array()

于 2012-11-24T17:44:03.937 に答える