douyu4535 2011-12-02 06:12
浏览 149
已采纳

mysql_connect()使用http协议

I am trying to connect to a MySql server (not localhost) from my computer using the code below. It is giving this error:

Warning: mysql_connect() [function.mysql-connect]: [2002] Connection refused (trying to connect via tcp://10.6.3.6:3306) in on line 7

I wonder if we can use the http protocol to connect instead of tcp that is being used by default? I searched quite a bit on how to change the protocol, but most of the answers were describing how to connect to localhost, and not much about how to connect to another server. Please help.

PS: I am able to connect to the server by going to http://10.6.3.6/phpmyadmin/...). So I am sure the server is up.

My Code

<?php

$db_hostname = '10.6.3.6';
$db_database = 'db_user11';
$db_username = 'db_user11';
$db_password = '########';

$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database, $db_server)
or die("Unable to select database: " . mysql_error());

?>
  • 写回答

4条回答 默认 最新

  • duanna5749 2011-12-02 06:19
    关注

    First of all, HTTP is layered on top of TCP/IP.
    In order to connect to something via HTTP, it needs to run an HTTP server. MySQL does not run an HTTP server and there's no current/realistic/supported way to tunnel an SQL connection through HTTP. Even if there was, HTTP is not exactly the best protocol for this.

    In short: no. You're trying to solve the wrong problem. You need to configure your MySQL server to allow connections from other machines over the network, give the user you're trying to connect with appropriate permissions to connect from other machines and make sure the MySQL server is reachable from other machines.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM