-
December 13th, 2007, 01:01 AM
#1
PHP - SQL problem
I have been working on a website recently that needs to contain databases with things like emails (used as user name), passwords, and other information on the user. The problem I have been having is accessing the database using PHP. When I view this file in my browser, it only shows "connecting..." and doesn't continue with anything. I called the tech support, and that is the information they said to use, but its not working. I figured even if the information wasn't correct, it should go to the IF statement that displays an error, but that doesn't happen. Here is code that I have attempted to use to connect to the database. The domain is registered with Register.com if that helps. As you can tell, I am very new to PHP and SQL, so any help would be greatly appreciated.
Code:
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and
* outputs settings.
*/
echo "<html>
<head><title>Test MySQL</title></head>
<body>";
$host="sql5c6a.megasqlservers.com";
$user="dbm.restoretraditionalamerica.com";
$password="*";
echo "connecting...";
$cxn = mysqli_connect($host,$user,$password);
echo "connected";
$sql="SHOW STATUS";
$result = mysqli_query($cxn,$sql);
if($result == false)
{
echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
}
else
{
/* Table that displays the results */
echo "<table border='1'>
<tr><th>Variable_name</th>
<th>Value</th></tr>";
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
echo "<tr>";
$row_array = mysqli_fetch_row($result);
for($j = 0;$j < mysqli_num_fields($result);$j++)
{
echo "<td>".$row_array[$j]."</td>\n";
}
}
echo "</table>";
}
?>
</body></html>
-
December 13th, 2007, 02:16 AM
#2
Member
try with a simple script like this to see if it connects ok ->
Code:
// Connect to database.
@mysql_connect("localhost", "loginname", "password") or die('<font face="helvetica">At this time we are unable to connect to the Database.<br><br>The most likely cause is a problem with the server hosting the database.<br><br>Please try again later as these problems tend to be transient.<br><br>We apologise for the inconvenience.</font>');
@mysql_select_db("databasename") or die("Unable to select db");
If this works with your info, maybe there's a typo somewhere in the other script?
In this script too, "localhost" may need to be changed to the address of your ISP's server.
Cheers,
Niggles
-
December 13th, 2007, 11:42 PM
#3
I attempted to use localhost and the host i previously posted, both of which returned the answer: At this time we are unable to connect to the Database....
-
December 13th, 2007, 11:59 PM
#4
Have you verified username, host information, password etc etc?
your PHP connect to the MySQL database isn't working.
Also you have an error in your connection string.
$cxn = mysqli_connect
should be
$cxn = mysql_connect
-
December 14th, 2007, 08:06 AM
#5
That mysqli statement is correct if the MySQL is version 4.1 or above.
http://nl.php.net/manual/en/ref.mysqli.php
There is a slight flaw in the code though. The code doesn't check if the connection actually succeeded.
Add this and it may give you a clue why it's failing:
Code:
if (!$cxn) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
Oliver's Law:
Experience is something you don't get until just after you need it.
-
December 14th, 2007, 03:39 PM
#6
Ahh...shows you how adapt I am at programming...only do it when I have to..lol
-
December 14th, 2007, 09:13 PM
#7
Doesn't matter, I had to look up mysqli_ myself, I'm also used to seeing mysql_
This shows you how long it's been since I played with the stuff
It seems you can use mysql_ but the mysqli_ lets you make use of the features found in 4.1.0 and higher.
Last edited by SirDice; December 14th, 2007 at 09:16 PM.
Oliver's Law:
Experience is something you don't get until just after you need it.
-
December 15th, 2007, 07:38 AM
#8
Junior Member
Don't suppress your error messages in your test scripts. That's kind of counter-productive, no?
My thoughts.
-
December 15th, 2007, 04:55 PM
#9
You have to isolate your problem so id comment out a bunch of code and see if it gets that far
-
December 15th, 2007, 05:56 PM
#10
The problem is it gets to line
echo "connecting...";and is fine, but it seems to stop on the next line.
I don't really know what you'd want me to comment out, because I know where its hanging, I just don't know what to do about it.
Similar Threads
-
By catch in forum The Security Tutorials Forum
Replies: 27
Last Post: August 9th, 2006, 08:01 AM
-
By nightcat in forum The Security Tutorials Forum
Replies: 9
Last Post: May 28th, 2005, 02:47 AM
-
By HDD in forum Other Tutorials Forum
Replies: 2
Last Post: February 1st, 2004, 08:05 PM
-
By mantra in forum AntiOnline's General Chit Chat
Replies: 6
Last Post: January 6th, 2003, 09:18 AM
-
By yuna_admirer in forum Programming Security
Replies: 4
Last Post: December 14th, 2002, 03:19 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|