12
4

3 に答える 3

17
于 2012-11-28T04:40:59.220 に答える
14

It could be happening in a couple of places: 1) the query itself, or 2) the creation of the mysqli instance (and resulting db connection). If I had to guess, I suspect your problem is (2).

One quick-and-dirty debugging method is to use microtime().

http://www.php.net/manual/en/function.microtime.php

Example:

$start = microtime(TRUE); // Start counting

$mysqli = new mysqli('localhost', 'root', '', 'testdb');

$temp = microtime(TRUE) - $start;
echo "Time to connect: {$temp}";  // Check elapsed time

$mysqli->set_charset("utf8");
if(mysqli_connect_errno()) {
    echo "Connection Failed: " . mysqli_connect_errno();
    exit();
}

$temp = microtime(TRUE) - $start;
echo "Time to setup: {$temp}";  // Check elapsed time

$testreceive = $_POST['test_id'];
$query = "SELECT First_Name from tblperson";
$result = $mysqli->query($query);

$temp = microtime(TRUE) - $start;
echo "Time to query: {$temp}";  // Check elapsed time

$row = $result->fetch_all(MYSQLI_ASSOC);

$temp = microtime(TRUE) - $start;
echo "Time to fetch {$temp}";  // Check elapsed time
于 2012-11-28T04:46:08.263 に答える
0

The problem is the localhost lookup from localhost to 127.0.0.1.

The solution is to either add the line 127.0.0.1 localhost to your windows hosts file as @Wap has answered (and thank you for you answer!)

Or if you do not have access to the hosts file, you can simply change localhost to 127.0.0.1 in your php mysqli call: $mysqli = new mysqli('127.0.0.1'), 'root', '', 'testdb');

于 2015-04-30T17:15:24.540 に答える