PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #1526

mysqli DSN needs socket to work

Details

Submitted2004-05-28 16:00 UTC
Fromjl at lusidor dot se
Assigneddanielc
StatusNo Feedback
PackageDB
PHP Version5.0.0RC2 (Release Candidate 2)
OSFreebsd
Roadmaps(Not assigned)

Comments

[2004-05-28 16:00 UTC] jl at lusidor dot se

Description:
------------
Hi I run DB 1.6.4 with mysqli driver.
If I dont supply socket the connection fails.
Is this normal behaviour? I need to connect with
'socket' => '/tmp/mysql.sock' in the dsn array to get it to work.
It seems if you supply any value for the 6th parameter as you do in the driver it must be correct and not false/null.

mysqli_connect ( [string host [, string username [, string passwd [, string dbname [, int port [, string socket]]]]]])

[2004-05-28 16:50 UTC] jl at lusidor dot se

require('DB.php');

$conn = new mysqli("localhost", "uname", "pword", "dbase");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", $conn->host_info);
$conn->close();

$conn = mysqli_connect("localhost", "uname", "pword", "dbase");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", $conn->host_info);
$conn->close();

$link = mysqli_init();
mysqli_real_connect($link, 'localhost', 'my_user', 'my_password', 'world');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf ("Connection: %s\n.", mysqli_get_host_info($link));

mysqli_close($link);

$dsn = array(
'phptype' => 'mysqli',
'username' => 'uname',
'password' => 'pword',
'hostspec' => 'localhost',
'database' => 'dbase',
'socket' => '/tmp/mysql.sock',
);

$dsn2 = array(
'phptype' => 'mysqli',
'username' => 'uname',
'password' => 'pword',
'hostspec' => 'localhost',
'database' => 'dbase',
);

$conn = DB::connect($dsn);works fine
$conn = DB::connect($dsn2);
print_r($conn); // DB_Error object

Host information: Localhost via UNIX socket
Host information: Localhost via UNIX socket
Connection: Localhost via UNIX socket.
DB_Error Object
(
[error_message_prefix] =>
[mode] => 1
[level] => 1024
[code] => -24
[message] => DB Error: connect failed
[userinfo] => [nativecode=Can't connect to local MySQL server through socket '' (2)] ** Array
[backtrace] => Array
(
[0] => Array
(
[file] => /usr/local/lib/php/DB.php
[line] => 748
[function] => PEAR_Error
[class] => DB_Error
[type] => ->
[args] => Array
(
[0] => DB Error: connect failed
[1] => -24
[2] => 1
[3] => 1024
[4] => [nativecode=Can't connect to local MySQL server through socket '' (2)]
)

)

[1] => Array
(
[file] => /usr/local/lib/php/PEAR.php
[line] => 536
[function] => DB_Error
[class] => DB_Error
[type] => ->
[args] => Array
(
[0] => -24
[1] => 1
[2] => 1024
[3] => [nativecode=Can't connect to local MySQL server through socket '' (2)]
)

)

[2] => Array
(
[file] => /usr/local/lib/php/DB/common.php
[line] => 500
[function] => raiseError
[class] => DB_mysqli
[type] => ->
[args] => Array
(
[0] =>
[1] => -24
[2] =>
[3] =>
[4] => [nativecode=Can't connect to local MySQL server through socket '' (2)]
[5] => DB_Error
[6] => 1
)

)

[3] => Array
(
[file] => /usr/local/lib/php/DB/mysqli.php
[line] => 153
[function] => raiseError
[class] => DB_mysqli
[type] => ->
[args] => Array
(
[0] => -24
[1] =>
[2] =>
[3] =>
[4] => Can't connect to local MySQL server through socket '' (2)
)

)

[4] => Array
(
[file] => /usr/local/lib/php/DB.php
[line] => 393
[function] => connect
[class] => DB_mysqli
[type] => ->
[args] => Array
(
[0] => Array

[2004-05-28 16:53 UTC] jl at lusidor dot se

Do you need anymore info?