-1

我正在尝试使用以下脚本:https ://developers.google.com/maps/articles/phpsqlajax

谷歌调用这个脚本:phpsqlajax_genxml.php

我检查了 php_domxml 扩展并重新启动了我的 wampserver。我正在运行 php 5.2.9-2。

我在名为 phpsqlajax_dbinfo.php 的脚本中为每个指令定义了 $username、$password 和 $database。

它导致错误。你知道是什么导致了这些问题吗?

警告:domnode::append_child() 期望参数 1 是对象,在第 7 行的 E:\wamp\www\phpsqlajax_genxml.php 中给出了 null

注意:使用未定义的常量 localhost - 在第 10 行的 E:\wamp\www\phpsqlajax_genxml.php 中假定为“localhost”

注意:未定义变量:第 10 行 E:\wamp\www\phpsqlajax_genxml.php 中的用户名

注意:未定义变量:第 10 行 E:\wamp\www\phpsqlajax_genxml.php 中的密码

警告:mysql_connect() [function.mysql-connect]:第 10 行 E:\wamp\www\phpsqlajax_genxml.php 中的用户 'ODBC'@'localhost' 的访问被拒绝(使用密码:NO)未连接:访问被拒绝用户'ODBC'@'localhost'(使用密码:否)`

          // Start XML file, create parent node
          $doc = domxml_new_doc("1.0");
          $node = $doc->create_element("markers");
          $parnode = $doc->append_child($node);

          // Opens a connection to a mySQL server
          $connection=mysql_connect ("localhost", $username, $password);
          if (!$connection) {
            die('Not connected : ' . mysql_error());
          }

          // Set the active mySQL database
          $db_selected = mysql_select_db($database, $connection);
          if (!$db_selected) {
            die ('Can\'t use db : ' . mysql_error());
          }

          // Select all the rows in the markers table
          $query = "SELECT * FROM markers WHERE 1";
          $result = mysql_query($query);
          if (!$result) {
            die('Invalid query: ' . mysql_error());
          }

          header("Content-type: text/xml");

          // Iterate through the rows, adding XML nodes for each
          while ($row = @mysql_fetch_assoc($result)){
          // ADD TO XML DOCUMENT NODE
          $node = $doc->create_element("marker");
          $newnode = $parnode->append_child($node);

          $newnode->set_attribute("name", $row['name']);
          $newnode->set_attribute("address", $row['address']);
          $newnode->set_attribute("lat", $row['lat']);
          $newnode->set_attribute("lng", $row['lng']);
          $newnode->set_attribute("type", $row['type']);
         }

         $xmlfile = $doc->dump_mem();
         echo $xmlfile;

         ?>
          `
4

2 回答 2

1

要正确使用您在网络上找到的任何示例代码,您将始终必须在代码中定义任何未定义或示例变量。

在页面https://developers.google.com/maps/articles/phpsqlajax上,实际上在代码开头需要一个文件。

require("phpsqlajax_dbinfo.php");

该文件上的代码是。

<?
$username="username";
$password="password";
$database="username-databaseName";
?>

您必须创建该文件并为每个变量填写正确的信息。或者您可以放置​​和定义它们,而不是使用 require('file') 方法。

于 2012-05-10T01:34:28.973 回答
0

$username 和 $password 没有在我所看到的任何地方设置,所以在这一行上废话:

$connection=mysql_connect ("localhost", $username, $password);

于 2012-05-10T01:09:56.023 回答