Here's what I'm doing. In PHP I've written a db_connect.php that I include in every php file that needs it.
Code: Select all
<?php
error_reporting(E_STRICT);
error_reporting(-1);
ini_set('display_errors',1);
$dbInfo = parse_ini_file('/db_connect/db.in');
define ("HOST", $dbInfo["HOST"]); // The host you want to connect to.
define("USER", $dbInfo["USER"]); // The database username.
define("PASSWORD", $dbInfo["PASSWORD"]); // The database password.
define("DATABASE", $dbInfo["DATABASE"]); // The database name.
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
// If you are connecting via TCP/IP rather than a UNIX socket remember to add the port number as a parameter.
if (!$mysqli) {
die('fail');
} else {
echo 'success';
}
var_dump($mysqli);
echo '<br>';
var_dump(mysqli_connect_error());
If ((USER == "USERNAME HERE") || (PASSWORD == "PASSWORD HERE")){
print 'ERROR - Please set up the script first';
exit();
}
?>the var dump on $mysqli is identical regardless of if I point it to the actual file or to a bogus file name.
Code: Select all
object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(6) "5.5.32" ["client_version"]=> int(50532) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(23) "5.5.32-0ubuntu0.12.10.1" ["server_version"]=> int(50532) ["stat"]=> string(135) "Uptime: 8944 Threads: 1 Questions: 2445 Slow queries: 0 Opens: 275 Flush tables: 1 Open tables: 67 Queries per second avg: 0.273" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(468) ["warning_count"]=> int(0) }When I try putting:
Code: Select all
echo 'Success... ' . $mysqli->host_info . "\n";Code: Select all
Success... Localhost via UNIX socket