?
Solved

mysql_pconnect() probem

Posted on 2010-09-11
9
Medium Priority
?
681 Views
Last Modified: 2012-05-10
Hi, I developed a blog site  few yeas ago I wish to re hash.  Using Dreamweaver when I try to run on localhost ( I am using a Mac OSX 10.6.4........php based with mysql on apache).

I get this error message:

Warning: mysql_pconnect() [function.mysql-pconnect]: [2002] Socket operation on non-socket (trying to connect via unix:///var/mysql/mysql.sock) in /Library/WebServer/Documents/myblog/Connections/connBlog.php on line 9

Warning: mysql_pconnect() [function.mysql-pconnect]: Socket operation on non-socket in /Library/WebServer/Documents/myblog/Connections/connBlog.php on line 9

Fatal error: Socket operation on non-socket in /Library/WebServer/Documents/myblog/Connections/connBlog.php on line 9

The coding for connBlog is:

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connBlog = "localhost";
$database_connBlog = "myblogdata2";
$username_connBlog = "root";
$password_connBlog = "root";
$connBlog = mysql_pconnect($hostname_connBlog, $username_connBlog, $password_connBlog) or trigger_error(mysql_error(),E_USER_ERROR);
?>

I've spent a few hours Googling (scrabble allowable !) and have not found a satisfactory answer.

So I need pro help please.

Cheers   Jim


0
Comment
Question by:jim_pilot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Expert Comment

by:maxxerific
ID: 33653903
Is this a local site or hosted remotely?  
If its been a while, its possible that the port/socket has changed on the reote server.
You can ask your host provider if they have 'unusual' mysql connection parameters.

 
Secondly, i have personally run into problems with pconnect on certain servers.
Have you tried connecting without persistence i.e. mysql_connect ()

do you get the same error?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33653959
Make sure MySQL is running.
0
 

Author Comment

by:jim_pilot
ID: 33654078
Hi guys, thanks for quick replies.

My site is being hosted locally, hence localhost, and yes MySql server is running as is Apache.

Re persistence, can you give me quick example to use mysql_connect () please ??

ta.
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 
LVL 1

Assisted Solution

by:maxxerific
maxxerific earned 1000 total points
ID: 33654130
hey Jim:
  when I say 'locally', i mean are you running the server yourself? Or is the site/server itself on a remote machine (do you pay for a hosting company....or do you administer a server at home, for example)?

[The term 'localhost' does not specify which scenario, as it is only relevant to the script - in this case i would assume connBlog.php - which is trying to exectute databse  connection commands.]

I ask this because if you are running your own server, you will be able to poke around in the mysql conifg files and ultimately have greater control over troubleshooting.

 
You use mysql_connect like mysql_pconnect. But once you have retrieved your information, it is good practice to send terminating connection commands:


for example:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
0
 

Author Comment

by:jim_pilot
ID: 33654225
Gidday,

my site is totally located and hosted on my Mac laptop.

I found this on the MySql site:  http://forums.mysql.com/read.php?25,72797,79252

which says when upgrading to Snow Leopard I need to update MySql, grrrrr

So I will give that a whirl and let you know how it goes.  I might need to try your suggested coding, ta.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33662225
Given the nature of most HTTP requests and the way PHP works to generate pages, the pconnect() functions do not really add any value -- each page is an atomic request.  Here is how I set up the MySQL environment.
<?php // RAY_mysql_example.php
error_reporting(E_ALL);


// IMPORTANT PAGES FROM THE MANUALS
// MAN PAGE: http://us2.php.net/manual/en/ref.mysql.php
// MAN PAGE: http://us2.php.net/manual/en/mysql.installation.php
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-error.php


// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB CONNECTION: ";
   echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB SELECTION: ";
   echo "<br/> $errmsg <br/>";
   die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES

Open in new window

0
 

Author Comment

by:jim_pilot
ID: 33664150
Hi Ray,

that looks interesting.  I'll have a chance on Thursday to "play" with it.  I'll be back by the weekend,
many thanks

Jim
0
 

Author Comment

by:jim_pilot
ID: 33687609
Hi Ray,

I've just tried your coding, thank you, but still get "MySql Error #: 2002, Socket operation on  non-socket.

I suspect I really need to reload MySql as suggested in:
http://forums.mysql.com/read.php?25,72797,79252 

I'll do so next week when I get back to Sydney and let you know how I go.

Thanks guys,
Cheers  Jim  :)

 
0
 

Accepted Solution

by:
jim_pilot earned 0 total points
ID: 33750254
Hi,
I have finally had the time to delete the old MySql ad re-install and everything now works fine.

Seems the problem was that you need to remove and re-instal MySql with OSX 10.6

For anyone else who finds this this problem this link was most helpful with the sock:

http://www.simonwhatley.co.uk/installing-mysql-on-mac-osx-10-6-snow-leopard


$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock


Thanks guys,
best wishes
Jim :)
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question