Solved

mysql_pconnect() probem

Posted on 2010-09-11
9
678 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 look for a specific file type in a local or remote server directory using PHP.

691 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