Warning: mysql_connect()

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

Post Reply
ticklefishdesign
Forum Newbie
Posts: 4
Joined: Tue Jul 22, 2008 8:30 am

Warning: mysql_connect()

Post by ticklefishdesign »

Hi everyone,

This is my first post and i'm also new to php.

Well i'm installing a site with many php files and have come across a problem, this is the error that comes up on the site and i dont really know what to do, I thought it was to do with ssl being set up which i have gone and done on new hosting but this same msg still comes up, Any help would be great.

Warning: mysql_connect() expects parameter 5 to be long, string given in /home/rooftrad/public_html/classes/db_class.php on line 49
Couldn't connect to database


Many thanks,
John
ticklefishdesign
Forum Newbie
Posts: 4
Joined: Tue Jul 22, 2008 8:30 am

Re: Warning: mysql_connect()

Post by ticklefishdesign »

Ok i've now set a new user on the database with all permissions and changed user and password this is now the error i get;

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'rooftrad_rooftra'@'localhost' (using password: YES) in /home/rooftrad/public_html/incs/dbconn.php on line 13
Couldn't connect to database

Any ideas?

Thanks in advance,
Sephirangel
Forum Commoner
Posts: 45
Joined: Tue Jul 15, 2008 1:37 pm

Re: Warning: mysql_connect()

Post by Sephirangel »

ticklefishdesign, please post the code you are using to connect to the mysql server, and we can be of better help.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: Warning: mysql_connect()

Post by Chalks »

first, I would recommend not posting the password or username you actually used. That said, it sounds like you don't have the database set up correctly on your server. Go into your server's control panel, click over to mysql databases, and make sure the correct user is associated with the correct database.
ticklefishdesign
Forum Newbie
Posts: 4
Joined: Tue Jul 22, 2008 8:30 am

Re: Warning: mysql_connect()

Post by ticklefishdesign »

I've chaned the user and tested on a test page which shows that the access to the database is ok, but still im receiving this error;

Warning: mysql_connect() expects parameter 5 to be long, string given in /home/rooftrad/public_html/classes/db_class.php on line 49
Couldn't connect to database
manixrock
Forum Commoner
Posts: 45
Joined: Sun Jul 20, 2008 6:38 pm

Re: Warning: mysql_connect()

Post by manixrock »

provide the source code where you connect to the database.
ticklefishdesign
Forum Newbie
Posts: 4
Joined: Tue Jul 22, 2008 8:30 am

Re: Warning: mysql_connect()

Post by ticklefishdesign »

<?
$GLOBALS['_dbhost'] = 'localhost';
//$GLOBALS['_dbhost'] = '**.***.***.**';
$GLOBALS['_dbuser'] = '****';
$GLOBALS['_dbpassword'] = '*****';
$GLOBALS['_dbdatabase'] = '******';


//uses 'field' notation as key
function ExecSQL($SQL) {
$i=0;
$rArray = array();
$db_resource = mysql_connect($GLOBALS['_dbhost'],$GLOBALS['_dbuser'],$GLOBALS['_dbpassword'],false, MYSQL_CLIENT_SSL) or die ("Couldn't connect to database");
mysql_select_db($GLOBALS['_dbdatabase']);
$result = mysql_query($SQL);
if ( substr($SQL,0,6) == "SELECT" ) {
if ( $result != false && mysql_num_rows($result) > 0 ) {
while ( $result && ($row=mysql_fetch_assoc($result)) ) {
$rArray[$i] = $row;
$i++;
}
return $rArray;
}else {
return array();
}
}else if ( $result ) {
return true;
}else {
return false;
}
}

//uses 'table.field' notation as key
//NOTE: useful for queries with joins to multiple tables with the same field names.
// use split("\.", 'table.field' ); to seperate the sections
function ExecSQLLong($SQL) {
$i=0;
$rArray = array();
$db_resource = mysql_connect($GLOBALS['_dbhost'],$GLOBALS['_dbuser'],$GLOBALS['_dbpassword'],false, MYSQL_CLIENT_SSL) or die ("Couldn't connect to database");
mysql_select_db($GLOBALS['_dbdatabase']);
$result = mysql_query($SQL);
if ( substr($SQL,0,6) == "SELECT" ) {
if ( $result != false && mysql_num_rows($result) > 0 ) {
while ( $result && ($row=mysql_fetch_array($result, MYSQL_NUM)) ) {
$field_info = mysql_fetch_field($result, $i);
echo "<br>name: ".$field_info->name.", type: ".$field_info->type.", max_length: ".$field_info->max_length."/".mysql_field_len($result, $i);
$j=0;
$full_values = array();
foreach ( $row as $r ) {
$full_values[mysql_field_table($result, $j).".".mysql_field_name($result, $j)] = $r;
$j++;
}
$rArray[$i] = $full_values;
$i++;
}
return $rArray;
}else {
return array();
}
}else if ( $result ) {
return true;
}else {
return false;
}
}

function SQLError() {
return mysql_errno.": ".mysql_error();
}

function DbSafe($input) {
$input = str_replace("'", "`", $input);
return $input;
}
?>
manixrock
Forum Commoner
Posts: 45
Joined: Sun Jul 20, 2008 6:38 pm

Re: Warning: mysql_connect()

Post by manixrock »

As per one of the comments on mysql_connect()'s webpage: "MYSQL_CLIENT_SSL is not working, use MySQLi and mysqli->ssl_set()".

You can read it here: http://www.php.net/manual/en/function.m ... .php#77000
Post Reply