pb with mysql_connect

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
hello !

I've some problem using the mysql_connect function :nuts:.
This is the beginning of my script, that works fine on my own computer :

<?php
$con = mysql_connect("localhost:3306");
$db = "usr_ayantdroit";
if (!$con) {die('Connection impossible : ' . mysql_error());}
mysql_select_db($db, $con);


but it doesn't work on x10, bellow the error message :

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'usr'@'localhost' (using password: NO) in /home/usr/public_html/ident.php on line 4
Connection impossible : Access denied for user 'usr'@'localhost' (using password: NO)


line 4 is : $con = mysql_connect("localhost:3306"); (the second line above).

I presume either localhost:3306 is to be replaced... by what ? ; or I must declare something in phpmyadmin or in mysql ? But I don't know what exactly.

Does anyone can help me please ?

Thanks.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
mysql_connect("localhost", username, passwd );

It is just "localhost", no port number.

And you should consider using the mysqli_XXXX family of functions rather than the mysql_XXXX family. The 'i' is for 'improved'.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
To create a mysql user and database in cPanel, click on the mysql database wizard in the database section.
 

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
Thank you for your help.

I've created a user with password for my database, and I've suppressed the port number.

... and it works fine.

Thanks again. ;)
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
mysql_connect("localhost", username, passwd );

It is just "localhost", no port number.

And you should consider using the mysqli_XXXX family of functions rather than the mysql_XXXX family. The 'i' is for 'improved'.

Definitely right on the improved vs regular mysql. However, the port is implicitly added whether you specify it explicitly or not, but you are better off not specifying it and letting PHP get it from the php config settings.
 
Top