Jump to content

need help on connection with database


ramu_rp2005

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.

Link to comment
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");
?>
Link to comment
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.
Link to comment
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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.