【问题标题】:Why is this SQL in this PHP not working?为什么这个 PHP 中的这个 SQL 不起作用?
【发布时间】:2017-06-19 05:00:40
【问题描述】:

此 PHP 脚本中的我的 SQL 无法连接到我的 XAMMP 服务器上的 phpmyadmin-database:

<?php
//Shows every Error
error_reporting('E_All');
//used Host
define('MYSQL_HOST ', 'localhost');
//Name of SQL user
define('MYSQL_USER', 'root');
//Password of User
define('MYSQL_PASSWORD', '');
//Name of database
define('MYSQL_DATABASE', 'phpmodul');
?>

<?php
$db_link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
if ($db_link)
{
    echo 'Connection OK:', print_r($db_link);
}
else
{
    die('No connection: ' . mysql_error());
}
?>

当我执行它时,它只打印No connection: php_network_getadressinfo failed: The Host is unkown. 我正在使用 PHP 5.2.0 版和 XAMPP 5.6.28 版

Edit1 将 mysqli_* 更改为 mysql_*

【问题讨论】:

标签: php mysql xampp


【解决方案1】:

我找到了解决办法:

<?php
$con = mysqli_connect("localhost","root","","phpmodul");

if (mysqli_connect_error())
  {
      echo "Connection not possible: " . mysqli_connect_error();
  }
else
  {
      echo "Connection succsessfully established.";
  }

?>

【讨论】:

    【解决方案2】:

    您好,亲爱的,我遇到了您的问题,

    请删除空格

    define('MYSQL_HOST', 'localhost');
    

    或替换行

    define('MYSQL_HOST ', 'localhost');
    

    define('MYSQL_HOST', 'localhost');
    

    【讨论】:

    • 只删除空间,你的代码工作正常 :) 希望你明白 :) 享受 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 2018-06-26
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多