win7下手动搭建wamp环境,碰到的几个坑总结下,
1.能正常访问php和html类型文件,但是访问项目文件时老是连接被重置,后来总结是数据库的问题,就写测试用例测试php能否成功调用数据库,
1 <?php 2 echo "mysql"; 3 4 $mysql_conf = array( 5 ‘host‘ => ‘127.0.0.1‘, 6 ‘db‘ => ‘drupal628‘, 7 ‘db_user‘ => ‘root‘, 8 ‘db_pwd‘ => ‘admin‘, 9 ); 10 $mysql_conn = @mysql_connect($mysql_conf[‘host‘], $mysql_conf[‘db_user‘], $mysql_conf[‘db_pwd‘]); 11 if (!$mysql_conn) { 12 echo "失败"; 13 die("could not connect to the database:\n" . mysql_error());//诊断连接错误 14 }else{ 15 echo "连接成功"; 16 } 17 18 ?>
mysql测试
1 <?php 2 echo "mysqli"; 3 4 $mysql_conf = array( 5 ‘host‘ => ‘127.0.0.1‘, 6 ‘db‘ => ‘drupal628‘, 7 ‘db_user‘ => ‘root‘, 8 ‘db_pwd‘ => ‘admin‘, 9 ); 10 11 $mysqli = @new mysqli($mysql_conf[‘host‘], $mysql_conf[‘db_user‘], $mysql_conf[‘db_pwd‘]); 12 if ($mysqli->connect_errno) { 13 echo "失败"; 14 die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误 15 }else{ 16 echo "成功"; 17 } 18 19 ?>
mysqli测试
实际是mysqli能连接成功,mysql连接不成功,phpinfo.php也显示模块都已正常加载,百思不得其解,直到找到这位大神的解答。
解决方法1:
- 在apache的配置文件 httpd.conf 中添加: LoadFile D:/PHP/php5.2.13/libmysql.dll(一试便好,我不存在2的错误)
- 修改\windows\system32\drivers\etc\hosts文件,把localhost指向127.0.0.1(因Windows7可解析IPv6,默认localhost指向是::1而非127.0.0.1)
2.不能自动定位首页
在httpd.conf中<Directory "F:/php_projects"></Directory>中 添加 DirectoryIndex index.html index.php default.html default.php指定默认首页
时间: 2024-10-29 20:30:00