Page 1 of 2

cannot connect to Mysql with php

Posted: Wed Jan 24, 2007 3:28 am
by dagadakrishna
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi this  is krishna kanth

Iam breaking my head with this problem.

i run my php file which is as follows

Code: Select all

<?php

echo "connecting wait.....";
$con = mysql_connect("localhost","peter","abc123");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
echo  mysql_error();

mysql_close($con);
?>

after running this file iam not getting any thing except "connecting wait....." as output ,
it is not connecting to database and even it is not giving "Could not connect:" message also

can anyone plz tell me the problem ,iam not at all understanding iam new to php and databases

bye waiting for reply..............


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 24, 2007 3:34 am
by jammr
Because you uh... have no query.

Posted: Wed Jan 24, 2007 3:38 am
by dagadakrishna
can u tell me in detail plz so that i will try. i didnt understood what it mean

Posted: Wed Jan 24, 2007 3:43 am
by dude81
you need to run atleast one query of MySQL.
Genereally after that people use

Code: Select all

mysql_select_db($con,'yourdbname') or die(mysql_error()."your connected to db but db not found");

Posted: Wed Jan 24, 2007 3:50 am
by dagadakrishna
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I tried according to u what u told ,but that also not working and this is my code

Code: Select all

<?php 

echo "connecting wait....."; 
$con = mysql_connect("localhost","dagada1","dagada"); 

mysql_select_db($con,'kanth') or die(mysql_error()."your connected to db but db not found"); 


if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 


mysql_close($con); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 24, 2007 4:10 am
by dude81
try this from commandline
if system is Linux

Code: Select all

mysql -udagada1 -p
Later give the password, if you are able to connect then it should be fault with your installation of php. In this case you check with phpinfo(); function for Mysql is enable in php or not. Hoppe this could be the problem

Posted: Wed Jan 24, 2007 4:28 am
by dagadakrishna
this is also not working when i give

mysql -udagada1 -p

this command in command prompt it is not connecting.what will the the problem

if php is not installed properly means php scripts should not work but up to now i ran so many php scripts they worked properly,

might be not configured properly in the sence what it mean can u tell me how to configure

as per my knowledge have done like this

i gave extension_dir =libmySQL.dll in php.ini

i copied libmySQL.dll to windows/win32 directry

and i copied php.ini file to windows dir

and my os is windows xp not linux

Thanks
krishna kanth

Posted: Wed Jan 24, 2007 4:33 am
by dude81
Ok, tell me how did you create the user dagadda, from where, does it have a permissions.
I mean to say php-mysql is not working, not whole php.
Jus run phpinfo(); function and check for Mysql is there or not

Posted: Wed Jan 24, 2007 4:38 am
by dibyendrah
dude81 wrote:try this from commandline
if system is Linux

Code: Select all

mysql -udagada1 -p
Later give the password, if you are able to connect then it should be fault with your installation of php. In this case you check with phpinfo(); function for Mysql is enable in php or not. Hoppe this could be the problem
Should be like this

Code: Select all

mysql -u dagada1 -p

Posted: Wed Jan 24, 2007 4:45 am
by dude81
Are you a teacher by profession :?: :D

Posted: Wed Jan 24, 2007 5:26 am
by dagadakrishna
ni dagada1 simply i gave i did nt get it from somewhere i thought that whatever name we give it will take like that i thought but password i gave while instaling Mysql

i ran phpinfo(); then it gave a large list in that


ODBC Support enabled
Active Persistent Links 0
Active Links 0
ODBC library Win32

Directive Local Value Master Value
odbc.allow_persistent On On
odbc.check_persistent On On
odbc.default_db no value no value
odbc.default_pw no value no value
odbc.default_user no value no value
odbc.defaultbinmode return as is return as is
odbc.defaultlrl return up to 4096 bytes return up to 4096 bytes
odbc.max_links Unlimited Unlimited
odbc.max_persistent Unlimited Unlimited

and sql.safe_mode Off Off like that it is mentioned means is SQL enabled or not ?

Posted: Wed Jan 24, 2007 5:30 am
by dude81
Can you see mysql support in it something with

MySQL and a blue box down. Anyhow, in windows you need to type user as root and passwors by default is blank i.e. '' or else try to connect with your password.

Posted: Wed Jan 24, 2007 5:41 am
by dibyendrah
dude81 wrote:Are you a teacher by profession :?: :D
No. I am not. But can give a suggestions :wink:

Posted: Wed Jan 24, 2007 5:41 am
by dagadakrishna
No in that List nowhere MySQL is there,mean MySQL word is not There in that list

Posted: Wed Jan 24, 2007 6:05 am
by dude81
That says that your php-mysql functions will not work.
Mostlpeople face problems on windows is that they cannot install PHP properly. So better go for xammp.
Suggestion:
Google for apachefriends. Download xampp. It has built in everything.
Why dont you go for xammp. it will give you all the basic necessites.