Page 1 of 1
database connection failed
Posted: Wed Jul 11, 2007 9:11 am
by gurjit
Hi,
I have mysql 5 installed on a microsoft windows server 2003. I want to connect to this mysql database from my linux server. Both servers are hosted with different companies and reside in different countries.
I am using the following to connect but i get the following error:
Warning: mysql_connect(): Lost connection to MySQL server during query in /var/www/vhosts/domain/httpdocs/dbs_connection.php on line 13
Lost connection to MySQL server during query
This is the code i'm using
Code: Select all
<?php
$hostname = "00.000.00.00";
$database = "mydb";
$username = "root";
$password = "password";
$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db("mydb",$conn);
?>
The Windows server does not have php installed but I believe I dont need this because the call is made from the linux server which has PHP 4 installed.
Any ideas what the problem may be?
Connects to Database
Posted: Wed Jul 11, 2007 9:27 am
by giliat
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Code: Select all
<?PHP
// Connects to Database
$connection = mysql_connect("your localhost","usser name","password")
or die ("could not connect to server");
$db = mysql_select_db ("database name",$connection)
or die ("could not select database");
//-- end off database connection prosess
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Jul 11, 2007 5:28 pm
by RobertGonzalez
try mysql_pconnect() and see if that changes the result.
Posted: Thu Jul 12, 2007 3:44 am
by gurjit
I tried mysql_pconnect()
and the following error showed
Warning: mysql_pconnect(): Lost connection to MySQL server during query in /var/www/vhosts/domain/httpdocs/dbs_connection.php on line 14
could not connect to server
Posted: Thu Jul 12, 2007 10:15 am
by RobertGonzalez
Can you post the first 20 lines of /var/www/vhosts/domain/httpdocs/dbs_connection.php? If you have connection details (like username and password) start them out.
Posted: Fri Jul 13, 2007 5:36 am
by gurjit
I had some code commented out at the top of the page, I have taken that out and run the script again and displayed the full code on the page and error message below.
So the full code taking out the commented code now is
Code: Select all
<?php
$connection = mysql_pconnect("**.***.**.**","********","********")
or die ("could not connect to server");
$db = mysql_select_db ("*********",$connection)
or die ("could not select database");
?>
AND THE ERROR READS
Warning: mysql_pconnect(): Lost connection to MySQL server during query in /var/www/vhosts/httpdocs/dbs_connection.php on line 2
could not connect to server
I'm wondering if this could be something to do with mysql drivers on the windows server. Would I need to make a dnsless odbc connection in windows with a new username and password?
Currently I use root details to try and logon.
Posted: Fri Jul 13, 2007 5:54 am
by Rovas
You shouldn' t have problems with the drivers for MySQL if the installation didn' t give any errors. My advice check the buglist for MySQL to see if it' s there and see a solution; check the settings on the linux server (permissions for the file and the setup of the database server).
hi
Posted: Fri Jul 13, 2007 6:57 am
by maani786
dear give mysql server listening port along with ip address
default port for mysql is 3306..
i have experienced this error and then i solved it by providing port address
your code will look like this:
Code: Select all
<?php
$hostname = "00.000.00.00";
$database = "mydb";
$username = "root";
$password = "password";
$conn = mysql_connect($hostname.":3306", $username, $password) or die(mysql_error());
mysql_select_db("mydb",$conn);
?>
OR
Code: Select all
<?php
$hostname = "00.000.00.00:3306";
$database = "mydb";
$username = "root";
$password = "password";
$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db("mydb",$conn);
?>
hopefully u will be connected..
----------------
maani janjua
Posted: Fri Jul 13, 2007 11:45 am
by gurjit
Thanks maani786 - I tried both solutions, same error as my first post
Lost connection to MySQL server during query
I personal think its going to be an issue with windows drivers, with linux trying to connect to a windows mysql driver. Works fine with linux to linux machines not a problem.
I'll have to look into it. Any solutions would be helpful.