Php 无法从数据库检索数据
晚上好, 我试图在用户按下submit后获取登录详细信息,但按下按钮后,会显示“网页不可用”。这是使用xampp 1.7.3的错误日志中的日志:Php 无法从数据库检索数据,php,xampp,Php,Xampp,晚上好, 我试图在用户按下submit后获取登录详细信息,但按下按钮后,会显示“网页不可用”。这是使用xampp 1.7.3的错误日志中的日志: [Sat Jan 07 00:49:52 2012] [notice] Child 3540: Child process is running [Sat Jan 07 00:49:52 2012] [notice] Child 3540: Acquired the start mutex. [Sat Jan 07 00:49:52 2012] [no
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Child process is running
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Acquired the start mutex.
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Starting 150 worker threads.
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Starting thread to listen on port 443.
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Starting thread to listen on port 80.
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Starting thread to listen on port 443.
[Sat Jan 07 00:49:52 2012] [notice] Child 3540: Starting thread to listen on port 80
以下是我连接数据库的方式:
?php
class connection
{
function connect($sql)
{
$server = "localhost";
$myDB = "gamehutdb";
//connection to the database
$dbhandle = mssql_connect($server)
or die("Couldn't connect to SQL Server $server");
//select a database to work with
$selected = mssql_select_db($myDB)
or die("Couldn't open database $myDB");
//execute the SQL query and return records
$result = mssql_query($sql);
//return result set
return $result;
//close the connection
mssql_close($dbhandle);
}
}
?
首先,您可以使用mssql_connect,它根据连接到Microsoft SQL Server。在您的评论中,您说您正在使用phpmyadmin。Phpmyadmin仅连接到MYSQL数据库,而不是sql server
不要使用mssql_connect,而是使用连接到MYSQL的东西。类似于或来处理您的数据库连接(虽然在我看来pdo更好)。我同意CountMurphy关于pdo的观点 此外,mssql还从php文档中获取其他参数 资源mssql_connect([string$servername[,string$username[,string$password[,bool$new_link=false]])) 也许您应该尝试提供用户名和密码 请尝试“root”和“”(因为您没有使用密码) 试试看这里 此外,您正在使用XAMPP。
XAMPP附带MySQL。您确定不应该使用mysql\u connect()而不是mssql\u connect()?您的问题是PHP问题。在PHP中启用错误报告并检查日志,或将错误输出到浏览器。顺便说一下,您应该正确地报告错误,而不是使用
die()
输出“错误消息”。我认为正确的方法是mssql\u connect($servername,$username,$password),否?如何使用dreamweaver启用错误报告?我使用的是phpmyadmin而不是ms sql server我对dreamweaver一无所知,但是如果您在php的开头放上这些行,它会打印错误:问题是:用户“ODBC”@“localhost”(使用密码:否)的访问被拒绝警告:mssql_connect()[函数.mssql connect]:无法连接到服务器:localhost您的代码无法工作:(我同意Lyrae的观点,你应该使用一些可以连接到mysql的东西!@user1114676-我认为你使用的是mysql而不是MSSQL。请仔细检查。如果你确实使用MSSQL,你提供的数据库用户名和/或密码是错误的