ramu_rp2005 Posted March 10, 2006 Share Posted March 10, 2006 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";elseecho "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. Quote Link to comment https://forums.phpfreaks.com/topic/4590-need-help-on-connection-with-database/ Share on other sites More sharing options...
rscott7706 Posted March 10, 2006 Share Posted March 10, 2006 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";elseecho "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");?> Quote Link to comment https://forums.phpfreaks.com/topic/4590-need-help-on-connection-with-database/#findComment-16048 Share on other sites More sharing options...
ramu_rp2005 Posted March 10, 2006 Author Share Posted March 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4590-need-help-on-connection-with-database/#findComment-16050 Share on other sites More sharing options...
keeB Posted March 10, 2006 Share Posted March 10, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/4590-need-help-on-connection-with-database/#findComment-16051 Share on other sites More sharing options...
ramu_rp2005 Posted March 10, 2006 Author Share Posted March 10, 2006 no.this is not working.page is displaying empty!!1 Quote Link to comment https://forums.phpfreaks.com/topic/4590-need-help-on-connection-with-database/#findComment-16053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.