Jump to content

Archived

This topic is now archived and is closed to further replies.

ramu_rp2005

need help on connection with database

Recommended Posts

hi,
i have executed the following lines of code in my php file to connect to mysql but the page is empty
MySQL is installed and the password is ramki.

<html>
<body>
<?php
$db = mysql_connect("localhost", "root", "ramki");
if($db)
echo "conn successful";
else
echo "conn not successful";
?>
</body>
</html>

the if condition, it is not displaying if or else part.
wht do i do now?is there any probem with php connecting to mysql.how do i test it.

Share this post


Link to post
Share on other sites
1. Is you logon ifo correct? In other words, is "root" really your user name? Seems a little out of place, but not inconceivable. Anyway, check that the three components are right.

2. Is your script on the website (or server) when you try to execute the script? It has to reside there, not your local computer.

3. I am new to PHP, but I am not sure if the PHP statement:

if($db)
echo "conn successful";
else
echo "conn not successful";
?>

will work without identifying you database.


Here is a statement that will connect you if you have a database (given you know the database name and replace "your_database_name" with the correct name.

<?php
$db = mysql_connect("localhost", "root", "ramki");
mysql_select_db("your_database_name");
?>

Share this post


Link to post
Share on other sites
no its not working.the page is empty!!

<html>
<body>
<?php
//echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
$db = mysql_connect("localhost", "root", "ramki");
$test=mysql_select_db("streamware");
if($test)
echo "successful";
else
echo "unsuccessful";
?>
</body>
</html>


this is my altered code.

Share this post


Link to post
Share on other sites
change..
[code]<?php
//echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
$db = mysql_connect("localhost", "root", "ramki");
$test=mysql_select_db("streamware");[/code]

to..

[code]<?php
//echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
$db = mysql_connect("localhost", "root", "ramki") or die("unable to connect");
$test=mysql_select_db("streamware") or die ("unable to select db");[/code]

and remove the rest :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.