doujiao1814 2014-11-13 08:50
浏览 31

php访问错误使用在另一个脚本中工作的凭据

I'm an iOS developer trying to update a bit 'o php to work with the mysqli_* stuff instead of the deprecated mysql_* stuff.

I know next to nothing about php/mysql, and I'm stuck. I'm using a script found at http://www.w3schools.com/php/php_mysql_select.asp, with changes to reflect my field names etc

When I call the following from a browser I get an access error (Connection failed: Access denied for user 'whoisit7'@'localhost' (using password: YES)). The server name, password and username etc I'm using all work with an existing script in a browser but not with this new one.

Can anyone point me at what I'm getting wrong?

<?php
$servername = "localhost";
$userName = "whoisit7_ios";
$password = "blahblahblah";
$dbName = "whoisit7_scathing";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT name, latitude, longitude FROM location where status = 1";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "name: " . $row["name"]. " - latlong: " . $row["latitude"]. " " . $row["longitude"]. "<br>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>
  • 写回答

4条回答 默认 最新

  • donglin9717 2014-11-13 09:06
    关注

    In PHP, variable names are case-sensitive. So, Change your connection variable names to:

    $servername = "localhost";
    $username   = "whoisit7_ios";
    $password   = "blahblahblah";
    $dbname     = "whoisit7_scathing";
    

    Read it if you are new to PHP: http://php.net/manual/en/language.variables.basics.php

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统