Please support our MySQL advertiser: Programming Forums
Views: 4835 | Replies: 4
![]() |
•
•
Join Date: Jun 2005
Posts: 12
Reputation:
Rep Power: 4
Solved Threads: 0
Below is the code I'm using to try and simply display the contents of a table...however, I'm getting the following errors:
Warning: mysql_query(): Can't connect to MySQL server on 'localhost' (10061) in d:\Customers\user######\www\dbtest.php on line 18
Warning: mysql_query(): A link to the server could not be established in d:\Customers\user######\www\dbtest.php on line 18
Query failed
any ideas of what may be wrong? The hosting company states that it is beyond a simple connection problem and involves scripting support that they can't help me with. They provided a connection string that works, but once I add any sort of PHP code, I immediately get errors.
Here's the working connection string they gave me:
<?php
$hostname = "myhostname, ####";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
$sqlConn=@mssql_connect($hostname, $username, $password);
?>
I also wasn't sure why the host name had a comma with a four digit number following. They also wouldn't explain that.
Any help on good places to look for examples or ideas for this specific example would be great. My end goal is to make a form to accept user information and write it to the table, but I can't even get to the point where I can display data already in the database.
Thanks,
Nolan
<html>
<head>
<title>MSSQL Connection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
$hostname = "myhostname";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
$sqlConn=@mssql_connect($hostname, $username, $password);
$query = "SELECT * FROM mytable ORDER BY fname";
$result = mysql_query($query) or die ("Query failed");
//number of rows in our result for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD>First Name</TD><TD>Last Name</TD><TD>E-mail</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from result set
if($i % 2) { //if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['fname']."</TD><TD>".$row['lname']."</TD><TD>".$row['email']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
</body>
</html>
Warning: mysql_query(): Can't connect to MySQL server on 'localhost' (10061) in d:\Customers\user######\www\dbtest.php on line 18
Warning: mysql_query(): A link to the server could not be established in d:\Customers\user######\www\dbtest.php on line 18
Query failed
any ideas of what may be wrong? The hosting company states that it is beyond a simple connection problem and involves scripting support that they can't help me with. They provided a connection string that works, but once I add any sort of PHP code, I immediately get errors.
Here's the working connection string they gave me:
<?php
$hostname = "myhostname, ####";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
$sqlConn=@mssql_connect($hostname, $username, $password);
?>
I also wasn't sure why the host name had a comma with a four digit number following. They also wouldn't explain that.
Any help on good places to look for examples or ideas for this specific example would be great. My end goal is to make a form to accept user information and write it to the table, but I can't even get to the point where I can display data already in the database.
Thanks,
Nolan
<html>
<head>
<title>MSSQL Connection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
$hostname = "myhostname";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
$sqlConn=@mssql_connect($hostname, $username, $password);
$query = "SELECT * FROM mytable ORDER BY fname";
$result = mysql_query($query) or die ("Query failed");
//number of rows in our result for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD>First Name</TD><TD>Last Name</TD><TD>E-mail</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from result set
if($i % 2) { //if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['fname']."</TD><TD>".$row['lname']."</TD><TD>".$row['email']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
</body>
</html>
•
•
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation:
Rep Power: 4
Solved Threads: 6
You have to indicate/select the database before the query is placed
[php]$dbhost = "hostname";
$dbuser = "dbuser";
$dbpass = "dbpwd";
$database = "dbname";
$sqlConn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Unable to connect!");
mysql_select_db($database) or die ("Unable to open database!");[/php]
The digit after the hostname is not necessary.
[php]$dbhost = "hostname";
$dbuser = "dbuser";
$dbpass = "dbpwd";
$database = "dbname";
$sqlConn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Unable to connect!");
mysql_select_db($database) or die ("Unable to open database!");[/php]
The digit after the hostname is not necessary.
Ecommerce-Web-Store.com Building Your e-Business.
Notice they are using a mssql connection, not mysql, they may need to specify the port to make a connection, depending on the MS SQL server is configured.
Firefox: no, its not the end all solution, it has its own issues and in time it will be just as insecure as IE, when its hit Firefox 6, if it makes it that far. Oh, and AOL pays for it, incase you didn't know.
Microsoft & Windows: If you hate it so much, move to linux, or bsd, or anything else, stop complaning and move on.
Good starting places: Gentoo Novell SUSE Fedora Core Apple
Microsoft & Windows: If you hate it so much, move to linux, or bsd, or anything else, stop complaning and move on.
Good starting places: Gentoo Novell SUSE Fedora Core Apple
•
•
Join Date: Jun 2005
Posts: 12
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
Originally Posted by Zachery
Notice they are using a mssql connection, not mysql, they may need to specify the port to make a connection, depending on the MS SQL server is configured.
yep....just realized that and got it straightened out with our hosting company. Just had to switch from SQL Server to MySQL since it was originally set up with SQL server....thanks for the help everyone.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode