Jump to content

How to connect to mysql on wlan


Go to solution Solved by mac_gyver,

Recommended Posts

I'm very new php.  Have been using mysql for many years but only on a pc (ie not networked).

I have set up a pc on my lan as a server and can access it from the local network.

I'm having trouble connecting to the mysql db installed on the server pc.

The following simple code echos 'start' as in first php line, nothing is output after that.  Not even 'Connection failed:'

<!DOCTYPE html>
<html>
<body>

<h1>test php</h1>

<?php
echo "start";
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = mysql_connect($servername, $username, $password);
echo "after";

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";?> 

</body>
</html>

The server is running Kubuntu 14.04

mysql V14.14

php V5.5.9-1ubuntu4.11
 

Hope someone has some ideas.

Link to comment
https://forums.phpfreaks.com/topic/298211-how-to-connect-to-mysql-on-wlan/
Share on other sites

  • Solution

do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? the most likely problem is that the mysql_ extension is not installed/enabled in your php configuration.

 

next, the mysql_ functions are obsolete and will be removed from php soon. you should be using the PDO (the best option as it has a more consistent interface) or mysqli_ database functions in your php code. the php version you are using will be throwing a php error at the mysql_connect() statement to alert you about this.

 

lastly, the mysql_ functions don't have an OOP style interface, so there is no ->connect_error properly at all to test. this in itself should be throwing a php error.

 

 

I have set up a pc on my lan as a server and can access it from the local network.

I'm having trouble connecting to the mysql db installed on the server pc.

Are you saying MySQL is installed on a different computer to the one you are using to connect to mysql with?  Then you cannot use localhost as the hostname. Instead you must specify the hostname/ipaddress for the server pc mysql is installed on.

 

To allow remote connections to MySQL you may need to

  • configure your firewall on the server pc to allow remote connections on port 3306.
  • configure the host permissions for the MySQL user account you are using to allow for remote connections.

Thanks, have set /etc/php5/apache2/php.ini as sugested then restarted apache

I added this to a simple index.php file

$db = new PDO('mysql:host=localhost;dbname=gwl', 'root', 'alex23');
echo "after";

Still no error reported and no echo after the call to PDO

there's no guarantee of what php.ini php is using. to find the php.ini that php is using, create a .php script file with the code - <?php phpinfo(); ?> in it and browse to the url of the file. the Loaded Configuration File line in the output is the php.ini that php is using.

you should have been getting php errors from your code. having php's errors turned on is critical for debugging problems.

 

if you still are not seeing any php errors, after deliberately introducing problems into your code, the settings for error_reporting/display_errors may be commented out or are using invalid (false values) settings. if you need help with the error settings, post the actual lines for them from your php.ini file.

Edited by mac_gyver
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.