简体   繁体   English

php看不到本地mysql服务器

[英]php can't see local mysql server

I'm just getting started trying to set up a server/website and have run into what is probably a very basic issue. 我刚刚开始尝试设置服务器/网站,并遇到了可能是一个非常基本的问题。 I'm getting a blank screen when I try to connect to my installed mysql server with a php script; 当我尝试使用php脚本连接到已安装的mysql服务器时,出现黑屏; eg 例如

<html>
<body>
<script src="http://protovis-js.googlecode.com/svn/trunk/protovis-r3.1.js" type="text/javascript"></script>

<?php 
echo "Connecting..."
$user="root";
$password="passwd";
$server="127.0.0.1";
mysql_connect($server,$user,$password);
echo "Connected.";

?>
</body></html>

shows "Connecting..." but never reaches "Connected". 显示“正在连接...”,但从未达到“已连接”。 There's nothing wrong with the code or database, since this did work within the browser in Aptana 2.05 (since uninstalled). 代码或数据库没有问题,因为它在Aptana 2.05(已卸载)中的浏览器中确实起作用。 It doesn't work within Firefox or Chrome. 在Firefox或Chrome中不起作用。 Aptana was using a different (older) version of PHP, 5.2; Aptana使用的是其他版本的PHP 5.2。 phpinfo() accessed from Chrome/Firefox was 5.3. 从Chrome / Firefox访问的phpinfo()是5.3。 The php.ini file contains extension=mysql.so; php.ini文件包含extension = mysql.so;。 otherwise I couldn't tell if the settings were correct or not. 否则我无法确定设置是否正确。 The tutorials I looked at didn't really cover this sort of thing... anybody know what to do? 我看过的教程并没有真正涵盖这种事情……有人知道该怎么做吗?

What browser you're using has nothing to do with whether the php script running on the server connects to a database or not. 您使用的浏览器与服务器上运行的php脚本是否连接到数据库无关。

I would suggest checking the server logs, or adding some code to actually check and see what's going on: 我建议检查服务器日志,或添加一些代码以实际检查并查看发生了什么:

$link = mysql_connect($server,$user,$password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

Your MySQL instance may be configured to not respond to localhost. 您的MySQL实例可能配置为不响应localhost。 There are two ways of connecting to a MySQL server; 有两种连接MySQL服务器的方法: through a network connection (ip and port) or socket connection, which only works on the machine it's working on. 通过网络连接(IP和端口)或套接字连接(仅适用于正在使用的计算机)。 Your MySQL server may be configured to listen to socket connections but not network. 您的MySQL服务器可能配置为侦听套接字连接,但不能侦听网络。

  1. Try connecting using the mysql command line tool as "mysql -h 127.0.0.1 -uroot -ppassword mysql" 尝试使用mysql命令行工具作为“ mysql -h 127.0.0.1 -uroot -ppassword mysql”进行连接
  2. Try running your PHP script from the command line instead of inside the browser. 尝试从命令行而不是在浏览器中运行PHP脚本。

Ha! 哈! Just didn't have the php5-mysql package installed. 只是没有安装php5-mysql软件包。 So evidently having php and mysql by themselves is not enough. 因此,显然仅靠php和mysql是不够的。 Installed php5-mysql, the connection worked. 安装了php5-mysql,连接正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM