cannot connect to Mysql with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

cannot connect to Mysql with php

Post 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]
jammr
Forum Newbie
Posts: 16
Joined: Mon Jan 22, 2007 12:10 am

Post by jammr »

Because you uh... have no query.
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

can u tell me in detail plz so that i will try. i didnt understood what it mean
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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");
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post 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]
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post 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
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Are you a teacher by profession :?: :D
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post 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 ?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

dude81 wrote:Are you a teacher by profession :?: :D
No. I am not. But can give a suggestions :wink:
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

No in that List nowhere MySQL is there,mean MySQL word is not There in that list
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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.
Post Reply