首先在官网上下载Apache,安装。安装完后在安装目录下找到httpd文件,打开httpd文件,找到:ServerName改为:localhost:80(根据实际情况改);改DocumentRoot "E:/Project/PHPProject"(根据实际项目所在目录来);改<Directory "E:/Project/PHPProject">(根据实际项目所在目录来);改DirectoryIndex index.php index.html(apache首页默认的文件,当然你也可以定义更多,优先查找前面的,没有的话再查找后面的);改LoadModule php5_module "D:/php/php5apache2_4.dll"(php解压后所在目录下的php5apache2_4.dll文件路径);改PHPIniDir "D:/php"(php解压后的目录);改AddType application/x-httpd-php .php .html .htm(让apache支持php、html、htm三种格式,当然你也可以定义更多格式);Apache配置完成。

第二步下载php,注意要下载Safe Thread版本的,Non Safe版本的里面没有php5apache2_4.dll文件,我刚开始下载错了,走了湾路。下载完后解压。打开解压目录,更改php.ini.develop为php.ini,打开php.ini,将;extension=php_curl.dll的百分号去掉(其他一样),改 extension_dir = "D:/PHP/ext";改date.timezone = Asia/Shanghai

第三步下载mysql,安装后配置php.ini,放开extension=php_mysqli.dll

访问mysql的代码如下:

 

<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as*/
'simon123', /* The password to use */
'jrdshop'); /* The default database to query */
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}

/* Send a query to the server */
if ($result = mysqli_query($link, 'select * from userinfo')) {
printf("<table>");

/* Fetch the results of the query */
while( $row = mysqli_fetch_assoc($result) ){
printf("<tr><td>%s</td><td>%s</td></tr>",$row['UserID'], $row['UserName']);
}
/* Destroy the result set and free the memory used for it */
printf("<table>");
mysqli_free_result($result);
}
/* Close the connection*/
mysqli_close($link);
?>