Solved

mysql_pconnect() probem

Posted on 2010-09-11
9
676 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
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 83

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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 1

Assisted Solution

by:maxxerific
maxxerific earned 250 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 109

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

837 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