开发者

php and mysql fulltext column not playing well together

开发者 https://www.devze.com 2023-03-31 10:09 出处:网络
I have the following: Localhost: php version 5.3.0 Remotehost: php version 5.2.17 The actual table is hosted on Remotehost, which is running mysql version 5.0.91

I have the following:

Localhost: php version 5.3.0 Remotehost: php version 5.2.17

The actual table is hosted on Remotehost, which is running mysql version 5.0.91

I have a table with a varchar 30 and a LONGTEXT column. When I run a SELECT statement on it directly through phpmyadmin, the both columns display fine on both localhost and remotehost.

Strange things happen when I mix in a bit of my own php. I run the same statement in PHP and it works fine on localhost. Running the exact php code on remotehost will return the varchar column as it should be but return blank for the LONGTEXT column.

Here is my php code: ("first" is a varchar 30 column and "last" is a LONGTEXT column)

public function myCoolFunction() {

    $stmt=mysqli_prepare($this->connection,"SELECT first,last FROM $this->tablename");
    mysqli_stmt_execute($stmt);

    $rows=array();

     mysqli_stmt_bind_result($stmt,$row->first,$row->last);

    while (mysqli_stmt_fetch($stmt)) {
     $rows[]=$row;
     $row=new stdCl开发者_C百科ass();
     mysqli_stmt_bind_result($stmt,$row->first,$row->last);

    }

}

print_r($rows) gives this:

stdClass Object
(
    [first] => Bob
    [last] => 
)
stdClass Object
(
    [first] => Jane
    [last] => 
)

I have no control over the version of mysql I run on remotehost, otherwise I'd try to upgrade remotehost.


You seem to be mixing up your syntax for statement result binding. I don't use MySQLi much but from reading the manual, it looks like you should be using something like this

mysqli_stmt_bind_result($stmt, $first, $last);
    // avoiding the object properties here just to be safe

while (mysqli_stmt_fetch($stmt)) {
    $row = new stdclass;
    $row->first = $first;
    $row->last = $last;
    $rows[] = $row;
}

mysqli_stmt_close($stmt);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号