Jump to content


Photo

need help on connection with database


  • Please log in to reply
4 replies to this topic

#1 ramu_rp2005

ramu_rp2005
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 March 2006 - 06:22 AM

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.



#2 rscott7706

rscott7706
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationLakeside CA

Posted 10 March 2006 - 06:56 AM

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");
?>

#3 ramu_rp2005

ramu_rp2005
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 March 2006 - 07:04 AM

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.

#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 10 March 2006 - 07:11 AM

change..
<?php
//echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
$db = mysql_connect("localhost", "root", "ramki");
$test=mysql_select_db("streamware");

to..

<?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");

and remove the rest :)

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#5 ramu_rp2005

ramu_rp2005
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 March 2006 - 07:15 AM

no.this is not working.page is displaying empty!!1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users