Mysqli_connect

software development

#1

Hello,

i’m currently upgrading my php scripts to use the latest technologies, and i’m trying to understand the mysqli_connect f functions.

it requires a socket parameter at the end, i suppose that would be the part where you typed /tmp/mysql5.sock at the hostname. but do you now just type “/tmp/mysql5.sock” as last parameter or do you need to type something else as well ?


#2

[quote]i’m trying to understand the mysqli_connect f functions.

it requires a socket parameter at the end, i suppose that would be the part where you typed /tmp/mysql5.sock at the hostname. but do you now just type “/tmp/mysql5.sock” as last parameter or do you need to type something else as well ?[/quote]
You might want to look a little more closely at the PHP manual section for that mysqli_connect. :wink:

If you do, you will note that the socket parameter, like the port parameter, is optional and is NOT required.

Just like when using mysql_connect,defaults are used when not specified. For instance:

<?php $db = mysqli_connect($host, $login, $pass, $dbName); ... ?>… will “just work” without the parameter. :wink:

–rlparker


#3

I know that, and thats not the issue.

The issue is when I want to specify a socket, in which format should I give it to the constructor ?


#4

I’m really sorry … I could have sworn that you posted earlier, “it requires a socket parameter at the end…”, but I must have been mistaken.

Ah! Well that’s a different issue. The answer to that question is you should use the correct one.

That said, I’ll bet you a beer that Google knows which constructor to use. Good luck with your project. :slight_smile:

–rlparker


#5

afraid google doesn’t on this one.

been travelling over many sites by now and they all just copy the examples given by the php.net websites, and those examples rely on the default parameters for port and socket as well…


#6

Why do you even want to do this? The normal connection method of supplying a hostname, username, and password works just fine and is a lot less prone to error.

In any case, I’m reasonably sure that the socket approach only works if your script is on the same machine as the one running the mysql server. In other words, you must be able to connect to your database on ‘localhost’. As a general matter, that isn’t the case on Dreamhost, so even if one of us could give you a socket name, it wouldn’t do you any good.

But anyway, sockets are just files in the filesystem. Whatever your socket’s filename is, that’s what you want to use.