@@ -62,20 +62,30 @@ public function __construct($dsn) {
62
62
*/
63
63
public function connect () : bool {
64
64
mysqli_report (MYSQLI_REPORT_OFF );
65
+
65
66
$ settings = parse_url ($ this ->dsn );
66
67
67
68
// If we can't even parse the DSN, don't bother
68
69
if (!isset ($ settings ['path ' ]) OR !isset ($ settings ['host ' ]) OR !isset ($ settings ['user ' ])) {
69
70
throw new \Skeleton \Database \Exception \Connection ('Could not connect to database: DSN incorrect ' );
70
71
}
71
72
72
- // We don't support connecting to UNIX sockets the traditional way
73
+ // UNIX sockets can be used by setting host to unix(/path/to/socket)
73
74
if ($ settings ['host ' ] == 'unix( ' ) {
74
- throw new \Skeleton \Database \Exception \Connection ('Could not connect to database: UNIX socket syntax is wrong ' );
75
+ $ settings ['socket ' ] = strtok ($ settings ['path ' ], ') ' );
76
+ $ settings ['path ' ] = strtok ('' );
77
+ $ settings ['host ' ] = 'localhost ' ;
78
+ } else {
79
+ $ settings ['socket ' ] = null ;
80
+ }
81
+
82
+ if (!isset ($ settings ['port ' ])) {
83
+ $ settings ['port ' ] = null ;
75
84
}
76
85
77
86
$ settings ['path ' ] = substr ($ settings ['path ' ], 1 );
78
- $ this ->database = @new \Mysqli ($ settings ['host ' ], $ settings ['user ' ], $ settings ['pass ' ], $ settings ['path ' ]);
87
+
88
+ $ this ->database = @new \Mysqli ($ settings ['host ' ], $ settings ['user ' ], $ settings ['pass ' ], $ settings ['path ' ], $ settings ['port ' ], $ settings ['socket ' ]);
79
89
80
90
// If there is an error connecting to the database, stop doing what you're doing
81
91
if ($ this ->database ->connect_errno != 0 ) {
0 commit comments