[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 695
  • Last Modified:

mysql_pconnect() probem

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
jim_pilot
Asked:
jim_pilot
2 Solutions
 
maxxerificCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
Make sure MySQL is running.
0
 
jim_pilotAuthor Commented:
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
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!

 
maxxerificCommented:
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
 
jim_pilotAuthor Commented:
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
 
Ray PaseurCommented:
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
 
jim_pilotAuthor Commented:
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
 
jim_pilotAuthor Commented:
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
 
jim_pilotAuthor Commented:
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

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now