douliang1900 2013-02-21 00:03
浏览 30
已采纳

localhost,Microsoft SQL和php

I just started learning PHP and MySQL, and I got stuck when trying to connect to my database from a PHP block. I have installed XAMPP and SQL Server Express 2012 on my machine. My server name is RAFAL-MAC and I selected 'Windows Authentication.'

I have a simple HTML page with PHP code in a file called search.php

the PHP code is

<?php
    $con = mysql_connect('RAFAL-MAC','RAFAL-MAC\Rafal','');
    if (!$con)
    {
        die( 'Could not connect: ' . mysql_error() ) ;
    }
    mysql_select_db("one", $con) or die(mysql_error());
?>

When I go to localhost:8080/search.php I get the following warning:

Warning: mysql_connect(): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server in C:\xampp\htdocs\search_submit.php on line 11 Could not connect: Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server

I tried searching similar problems online, but all of the threads are about remote connections. I am just trying to connect to my local SQL server.

Any hints? I apologize for any missing information. Thanks! :)

EDIT: I changed the server name to 'localhost'

Now I am getting this:

Access denied for user ''@'localhost' to database 'one'

  • 写回答

1条回答 默认 最新

  • dongruan6001 2013-02-21 00:12
    关注

    Since you'd like to connect to SQL Server Express 2012, all functions beginning with mysql* will fail - since these functions speak to MySQL servers.

    Please install Microsoft's MS SQL Server driver pack found here. From this page:

    Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server:

    1. Download SQLSRV30.EXE to a temporary directory
    2. Run SQLSRV30.EXE
    3. When prompted, enter the path to the PHP extensions directory
    4. After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps

    People in Microsoft's PHP driver forum should easily be able to answer your question, in case you still have problems after the installation of the driver.

    Additionally, if connecting to the local machine, try to use these addresses:

    • localhost
    • 127.0.0.1

    These two addresses always reference the local machine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入