LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 12-05-2004, 01:22 AM   #1
figure8car
LQ Newbie
 
Registered: Jul 2003
Location: Poulsbo, WA
Distribution: DreamLinux
Posts: 11

Rep: Reputation: 0
Question Lost connection to MySQL server during query


I have been using a Mandrake 10.1 box to learn how to use PHP and MySQL. So far its been more about learning how to use Linux, but that OK! The LAMP box (Linux Apache MySQL PHP) has been working well until I try to connect to a database from a remote client. When I do, I get the following message.

Warning: mysql_connect(): Lost connection to MySQL server during query in /var/www/html3/show_poll.php on line 10
Could not connect to db

This is the PHP code snippet that generates the message.

<?php
/*******************************************
Database query to get poll info
*******************************************/

// get vote from form
$vote=$_REQUEST['vote'];

// log in to database
if (!$db_conn = mysql_connect('192.168.1.11', 'poll', 'poll'))
{
echo 'Could not connect to db<br />';
exit;
};
?>

192.168.1.11 is the address of the remote client. Poll is used for both the user and password arguments, and user poll has been created in MySQL.I have also tried using the host name of the remote client in place of the IP address, which is k7n2xp. The server has an entry in the /etc/hosts file that describes the remote client.

/etc/hosts
192.168.1.11 k7n2xp

Strange error, especially since I can use an MySQL manager program like DBDesigner4 on the remote client to create databases and tables, and to perform query's and insert data. Any help will be greatly appreciated.

Linux localhost 2.6.8.1-10mdk-i586-up-1GB #1 Wed Sep 8 16:56:13 CEST 2004 i586
Apache-AdvancedExtranetServer/2.0.50 (Mandrakelinux/5mdk) mod_ssl/2.0.50 OpenSSL/0.9.7d PHP/4.3.8
 
Old 12-05-2004, 05:28 PM   #2
figure8car
LQ Newbie
 
Registered: Jul 2003
Location: Poulsbo, WA
Distribution: DreamLinux
Posts: 11

Original Poster
Rep: Reputation: 0
Check your MySQL Function Arguments

The problem is always simple, once you FIND it! I had two problems here, the first was the mysql_connect() function arquments I was using. The argument for host is the host of the MySQL database, not the remote host trying to connect. The second problem was the PHP code itself. I went to the ZEND website and looked up the mysql_connect() function and used the example code they had in place of the code I got from a instructional book (PHP and MySQL Web Development, 3rd Edition) and BINGO, it worked. Alot of troubleshooting. I thought I should answer my own post as I hate it when people post and then say, "nevermind, I found it". I don't care how stupid I look (comes natural for me), if it saves someone else from burning time, POST IT! Also, I don't know why this fixed it, the function call done in similar fashon. If any knows why, I would like to know.

<?php
/*******************************************
Database query to get poll info
*******************************************/

// get vote from form
$vote=$_REQUEST['vote'];

// log in to database
//if (!$db_conn = mysql_connect('192.168.1.15', 'poll', 'poll')) // old method
//{
// echo 'Could not connect to db<br />';
// exit;
//};


$db_conn = mysql_connect('192.168.1.15', 'poll', 'poll') // new method
or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';

mysql_select_db('poll') or die('Could not select database');


//@mysql_select_db('poll');
* mysql_connect
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2013: Lost connection to MySQL server during query kicap Linux - Software 0 11-23-2004 09:30 PM
Error: lost connection to MySQL server during query patpawlowski Programming 2 01-23-2004 08:56 AM
Mysql Error: Lost Connection to Mysql during query ramnath Programming 5 11-18-2003 01:27 PM
MySQL server connection problem aeshley Programming 1 03-05-2002 10:59 PM
connection to server lost every day jdh Linux - Networking 2 02-11-2002 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration