Link to home
Start Free TrialLog in
Avatar of Torquil Beavis
Torquil BeavisFlag for Canada

asked on

mysqli_connect error on wamp but not on remote server

When I use the following code on the remote server, it works when making DB calls.
DEFINE ('DB_USERNAME', 'abc');
DEFINE ('DB_PASSWORD', 'def');
DEFINE ('DB_SERVER', 'server_address:3306');
DEFINE ('DB_DATABASE', 'ghi');

$dbc = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
echo "mysqli_connect dbc = ".$dbc."<br>";

Open in new window

However, when I try the same on the wamp64 localhost on my Windows 7 Pro system I get the error message 'Object of class mysqli could not be converted to string'.
DEFINE ('DB_USERNAME', 'abc');
DEFINE ('DB_PASSWORD', 'def');
DEFINE ('DB_SERVER', 'localhost:3306');
DEFINE ('DB_DATABASE', 'ghi');

$dbc = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
echo "mysqli_connect dbc = ".$dbc."<br>";

Open in new window

Any ideas what's going on here?
Avatar of arnold
arnold
Flag of United States of America image

what is the relationship between the server_address and the localhost?
are both systems WAMP?

you need to assign the output from running

check whether both running the same version of php.....

$dbc is a connection pointer, why would you think to echo it out?
run queries and output the results, test whether $dbc is true (connection exists) false, connection failed.
You should always include test to make sure the mysqli_connection connected versus not
Avatar of Torquil Beavis

ASKER

what is the relationship between the server_address and the localhost?
are both systems WAMP?
=> The server_address is on a remote linux server with PHP 5.3
=> The localhost is on my desktop running PHP 5.6.25

$dbc is a connection pointer, why would you think to echo it out?
run queries and output the results, test whether $dbc is true (connection exists) false, connection failed.

=> $dbc shows as true on both localhost and server_address, but when I use it as follows, the message pops up. It seems to balk when used to test the cookie. Thus the echo test.
$cookie = mysqli_real_escape_string ($dbc, $cookie);

Open in new window

I would think that the PHP version shouldn't make any difference to $dbc
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is an explanation of the function and examples of its use.

You should use the site to make sure your use of functions are as they were intended.
http://php.net/manual/en/mysqli.real-escape-string.php
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent! I've made the changes and they work well.

Ray, that's a great E-E article. I'm working my way through the references for mysqli.

Thanks guys.