문제

I have changed some of my old queries to the Mysqli framework to improve performance. Everything works fine on localhost but when i upload it to the webserver it outputs nothing. After connecting I check for errors and there are none. I also checked the php modules installed and mysqli is enabled.

I am certain that it creates a connection to the database as no errors are displayed. (when i changed the database name string it gave the error)

There is no output from the query on the webserver, which looks like this:

$mysqli = new mysqli("server", "user", "password");

if (mysqli_connect_errno()) {
   printf("Can't connect Errorcode: %s\n", mysqli_connect_error());
   exit;
}

// Query used  
$query = "SELECT name FROM users WHERE id = ?";

if ($stmt = $mysqli->prepare("$query")) 
{

    // Specify parameters to replace '?'
    $stmt->bind_param("d", $id);  

    $stmt->execute();

    // bind variables to prepared statement 
    $stmt->bind_result($_userName);

    while ($stmt->fetch()) 
    {
          echo $_userName;
    }


    $stmt->close();
 }
}

//close connection 
$mysqli->close(); 

As I said this code works perfectly on my localserver just not online. Checked the error logs and there is nothing so everything points to a good connection. All the tables exists as well etc. Anyone any ideas because this one has me stuck! Also, if i get this working, will all my other queries still work? Or will i need to make them use the mysqli framework as well? Thanks in advance.

EDIT:

Ok Ive done some 'debugging' to see what is happening. There is data in the table i'm querying that matches the query. I did the following to check the prepare statement:

echo "debug 1";

if ($stmt = $mysqli->prepare("$shiftQuery"))  
{

echo "debug 2";
printf("Error: %s.\n", $stmt->error);

etc...
}

So basically it should output 'debug 1' before the statment is prepared (Which it does). Then after it should output 'debug 2' and any errors that occured.

The problem is here somewhere as it doesnt reach the debug 2 line in the IF statement. Since the connection details are fine, i cant really see why the $mysqli object wouldnt be created. That give anyone any further ideas???

thanks

올바른 솔루션이 없습니다

다른 팁

알리기 때문에 해당 설정 페이지에 대한 코드 내부 작동을 피하는 후에는 WebNavigationSettings 클래스를 읽고 GlobalNavigation.Source 속성 (a StandardNavigationSource enum )와 같은 :

if (PublishingWeb.IsPublishingWeb(web))
{
    WebNavigationSettings settings = new WebNavigationSettings(web);
    switch (settings.GlobalNavigation.Source)
    {
        case StandardNavigationSource.PortalProvider:
            // Data source is Structured Navigation
            break;
        case StandardNavigationSource.TaxonomyProvider:
            // Data source is Managed Navigation
            break;
        case StandardNavigationSource.InheritFromParentWeb:
            // Root navigation data source is inherited
            break;
        case StandardNavigationSource.Unknown:
            // The documentation for this value states:
            // "Returns a value of unknown to indicate an advanced configuration
            // that does not correspond to one of the standard configurations.
            // This value cannot be manually assigned to the Source property."
            break;
    }
}
else
{
    // Non-publishing site, root source is SPNavigation.TopNavigationBar
}
.

MySQL user permission is host sensitive -- it may give user1 from localhost and user1 from other host different permission.

GRANT ALL ON *.* TO user@'%' IDENTIFIED BY 'password';

Mysqli framework does not improve performance.
Error checking must be done not only after connect but after each query execute.

Check $stmt->error for errors
Or try to check against throwed exception

Is Id an integer? I normally run my mysqli like

$sql = "SELECT name FROM users WHERE id = ?";
            if($stmt = $mysqli->mysqli->prepare($sql)){
              $stmt->bind_param("i", $id);
                    if($stmt->execute()){
                        $stmt->bind_result($name);
                        $stmt->store_result();
                        if($stmt->fetch()){
                            return $name;
                         }else{
                             return 'Not Found';
                         }      
                    }else{
                        return 'Execute Error';
                    }

            }else{
                return 'SQL Error';
            }

Hope that helps

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top