HuaMin
January 19, 2010, 4:27am
1
Hi,
I’ve created such an HTML file like
<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php
$dbhost = ‘localhost:3306’;
$dbuser = ‘created_user’;
$dbpass = ‘password’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ’ . mysql_error());
}
echo ‘Connected successfully’;
mysql_select_db( ‘created_user’ );
mysql_close($conn);
?>
</body>
</html>
But I did not have any output from that. Any advice? When I’m connecting to the DB using dbForge studio, I don’t have problem at all (see the screen shots)
http://www.4shared.com/file/200074842/43203641/login_screen.html
What do you see when you enable error reporting?
error_reporting(E_ALL);
HuaMin
January 20, 2010, 6:16am
3
Many thanks Paul. I’ve put that. Now it’s like
<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php
error_reporting(E_ALL);
$dbhost = ‘localhost:3306’;
$dbuser = ‘created_user’;
$dbpass = ‘password’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ’ . mysql_error());
}
echo ‘Connected successfully’;
mysql_select_db( ‘created_user’ );
mysql_close($conn);
?>
</body>
</html>
but I still see any output.
Are you able to see anything when you have only the following as the php content?
<?php
echo phpinfo();
?>
If not, it might be the php settings that need to be tinkered with.
Speaking of which, what is your server environment?
HuaMin
January 20, 2010, 8:35am
5
Many many thanks.
I’ve put that like this
<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php echo phpinfo(); ?>
<?php
error_reporting(E_ALL);
$dbhost = ‘localhost:3306’;
$dbuser = ‘created_user’;
$dbpass = ‘password’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ’ . mysql_error());
}
echo ‘Connected successfully’;
mysql_select_db( ‘created_user’ );
mysql_close($conn);
?>
</body>
</html>
this is called index.html and it’s put in D:\xampp\htdocs\mysite2
But when I call this http://localhost/mysite2 , I still see nothing.
At the same time, I have another set of site programs in D:\xampp\htdocs\mysite and I can locate to the starting page of that, by http://localhost/mysite .
I haven’t used xampp before, but the standard for php files is to call them index.php
You might be running the risk that index.html is not being interpreted.
HuaMin
January 20, 2010, 8:59am
7
For that set of previous programs, I see that there’s only index.html (and no index.php). Any advice for that the above file is not showing anything?
My advice is that your php code is not responsible for the problem.
You will need to look further into the server setup, to resolve your issue.
HuaMin
January 20, 2010, 9:05am
9
Thanks. But do you see anything wrong in the above file?
As I said before, there is nothing wrong with the contents of file. The issue that you’re facing is not related to the contents of the file. The issue that you seem to be facing is that the server refuses to interpret it as PHP code.
SpikeZ
January 20, 2010, 9:16am
11
Paul has already told you the cause of the problem.
XAMPP Puts an index.html file in the root directory. This file is a simple frameset and so has no PHP code on it.
Rename your file to index.php and it will run fine.
It needs to be named with a php extention so that it can be parsed by the server before being sent to the browser.
HuaMin
January 20, 2010, 9:18am
12
Many thanks to all. I’ve renamed the file (to be index.php) and now when going to this http://localhost/mysite2/
I’ve got this page
http://www.4shared.com/file/202022051/b735c687/Selecting_MySQL_Database.html
HuaMin
January 20, 2010, 10:22am
13
Many many thanks. By the way, how can I export/import one Mysql user?
SpikeZ
January 20, 2010, 9:27am
15
Good stuff, that means its working fine.
Remove the
<?php echo phpinfo(); ?>
and you will be left with the last line
1Connected successfully
which is good
HuaMin
January 21, 2010, 1:45am
16
The 2 links are not available now. How to import one schema/user?
The two links that I provided work perfectly well.
You will experience problems though when you copy/paste the text description for the link, because the Forum itself puts in the ellipses so that they don’t take up too much room.
If all else fails, perform a search for xampp add mysql user and choose the first link that is for apache friends - xampp for windows
HuaMin
January 21, 2010, 3:54am
18
Many many thanks. Could you pls help on this?