我是一个PHP的菜鸟,刚装了apache,PHP5和MYSQL,想用下面的PHP脚本来测试与MYSQL的连接,命名为test-connect.php,IE上输入http://localhost/test-connect.php后,是一个空白页,请问高手们是怎么回事啊?
<html>
<head><title>MySQL Connection Test</title></head>
<body>
<?php
$conn = @mysql_connect("localhost", "root", "your-password");
if (!$conn)
die("<p>Error connecting to MySQL: <i>" . mysql_error() . "</i></p>");
echo("<p>Connected to Database Successfully.</p>");
if (!@mysql_select_db("DB-DEVEL", $conn))
die("<p>Error selecting DB-DEVEL database: <i>" . mysql_error() . "</i></p>");
echo("<p>Selected DB-DEVEL database successfully.</p>");
mysql_close ($conn);
echo("<p>Disconnected</p>");
?>
</body>
</html>
<html>
<head><title>MySQL Connection Test</title></head>
<body>
<?php
$conn = @mysql_connect("localhost", "root", "your-password");
if (!$conn)
die("<p>Error connecting to MySQL: <i>" . mysql_error() . "</i></p>");
echo("<p>Connected to Database Successfully.</p>");
if (!@mysql_select_db("DB-DEVEL", $conn))
die("<p>Error selecting DB-DEVEL database: <i>" . mysql_error() . "</i></p>");
echo("<p>Selected DB-DEVEL database successfully.</p>");
mysql_close ($conn);
echo("<p>Disconnected</p>");
?>
</body>
</html>
把 "@"这个符号去掉。
在php.ini里把显示错误的选项都打开。(可选)
phpinfo();
?>
把这段放在你的CODE里面,之后查查看有没有如下信息
mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.51a Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
你的phpinfo()里找不到mysql 或者是mysqli 这两个内容吗?
Build Date May 2 2008 18:01:20
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" "--with-extra-includes=C:\Program Files (x86)\Microsoft SDK\Include;C:\PROGRA~2\MICROS~2\VC98\ATL\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\MFC\INCLUDE" "--with-extra-libs=C:\Program Files (x86)\Microsoft SDK\Lib;C:\PROGRA~2\MICROS~2\VC98\LIB;C:\PROGRA~2\MICROS~2\VC98\MFC\LIB"
Server API CGI/FastCGI
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\WINDOWS\php.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
IPv6 Support enabled
Registered PHP Streams php, file, data, http, ftp, compress.zlib
Registered Stream Socket Transports tcp, udp
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.* This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference On On
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions no value no value
display_errors On On
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 6135 6135
expose_php On On
extension_dir ./ ./
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .;C:\php5\pear .;C:\php5\pear
log_errors Off Off
log_errors_max_len 1024 1024
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 30 30
max_input_nesting_level 64 64
max_input_time 60 60
memory_limit 8M 8M
open_basedir no value no value
output_buffering no value no value
output_handler no value no value
post_max_size 8M 8M
precision 12 12
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv On On
register_globals Off Off
register_long_arrays On On
report_memleaks On On
report_zend_debug On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_mode Off Off
bcmath
BCMath support enabled
calendar
Calendar support enabled