dstnlhhv791576 2012-08-23 05:12
浏览 45

mysql_connect始终允许访问

I am attempting to connect to a mySQL database running on my local computer using a local test server set up using XAMPP. I am just using the root account which has no password assigned. I tried it as below and everything appears to work fine. I got my message echoed out to say I had successfully connected. I then tried to force an error by entering anything else in as the host, username or password and it still echoes "connection successful".

This is the code I am using to connect:

<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "";

$myConn = mysql_connect($db_host, $db_username, $db_password) or die('Connection error: '.mysql_error());
echo 'connection successful';
?>

I was wondering whether it is me or maybe the install of apache/mySQL that I am using that is causing such an absurdity.

  • 写回答

3条回答 默认 最新

  • douza19870617 2012-08-23 05:16
    关注

    Something must be screwed up with your install:

    marc@panic:~$ php -a
    php > $x = mysql_connect('bleargh', 'foo', 'bar') or die(mysql_error());
    PHP Warning:  mysql_connect(): Unknown MySQL server host 'bleargh' (2) in php shell code on line 1
    Unknown MySQL server host 'bleargh' (2)marc@panic:~$ 
    

    About all I can think of is you've got a DNS server that returns a valid address for ALL lookups, causing all hostnames to resolve.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)