【问题标题】:Trouble with a google map script [closed]谷歌地图脚本的问题[关闭]
【发布时间】:2012-05-10 01:00:38
【问题描述】:

我正在尝试使用此脚本来自:https://developers.google.com/maps/articles/phpsqlajax

Google 调用此脚本: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' 的访问被拒绝(使用密码:否)未连接:用户 '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;

         ?>
          `

【问题讨论】:

  • 链接不起作用,请发布您的实际代码,否则我们不知道您是否进行了重大更改。您是否检查过 phpsqlajax_genxml.php 的第 7/10 行这些是您的错误所在,获得“访问被拒绝......使用密码:否”通常意味着您未能提供正确的 mysql 密码。再次没有代码很难知道
  • -1 这个问题不太可能帮助任何未来的访问者;它只与一个小地理区域、一个特定时间点或一个非常狭窄的情况相关,而这种情况通常不适用于互联网的全球受众。

标签: php javascript mysql xml


【解决方案1】:

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

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

require("phpsqlajax_dbinfo.php");

那个文件上的代码是。

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

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

【讨论】:

  • 我把它从复制/粘贴中去掉了,但它就在那里。
  • 你会得到一个“未定义的变量:用户名”的唯一原因是你使用 $username 时没有先说 $username = "something";
【解决方案2】:

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-09-13
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2013-01-18
  • 2011-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多