dousu1900
2017-02-02 07:56
浏览 51
已采纳

为什么这个PHP中的SQL不起作用?

My SQL in this PHP script cannot connect to my phpmyadmin-database on my XAMMP server:

<?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());
}
?>

When I execute it, it just prints No connection: php_network_getadressinfo failed: The Host is unkown. I am using PHP version 5.2.0 and XAMPP version 5.6.28

Edit1 Changed mysqli_* to mysql_*

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongquxiao8545 2017-02-02 08:25
    最佳回答

    I have found the solution:

    <?php
    $con = mysqli_connect("localhost","root","","phpmodul");
    
    if (mysqli_connect_error())
      {
          echo "Connection not possible: " . mysqli_connect_error();
      }
    else
      {
          echo "Connection succsessfully established.";
      }
    
    ?>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题