Page 1 of 1

Warning: mysql_connect()

Posted: Tue Jul 22, 2008 8:36 am
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

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 9:59 am
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,

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 2:48 pm
by Sephirangel
ticklefishdesign, please post the code you are using to connect to the mysql server, and we can be of better help.

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 3:04 pm
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.

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 8:05 pm
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

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 8:22 pm
by manixrock
provide the source code where you connect to the database.

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 8:30 pm
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;
}
?>

Re: Warning: mysql_connect()

Posted: Tue Jul 22, 2008 8:41 pm
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