Solved

mysql_pconnect() probem

Posted on 2010-09-11
9
668 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
9 Comments
 
LVL 1

Expert Comment

by:maxxerific
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
Make sure MySQL is running.
0
 

Author Comment

by:jim_pilot
Comment Utility
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
 
LVL 1

Assisted Solution

by:maxxerific
maxxerific earned 250 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jim_pilot
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now