Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysql中创建为INT的BIGINT_Php_Mysql_Wordpress_Bigint - Fatal编程技术网

Php 在mysql中创建为INT的BIGINT

Php 在mysql中创建为INT的BIGINT,php,mysql,wordpress,bigint,Php,Mysql,Wordpress,Bigint,我在wordpress中有一个mysql数据库表,在其中声明一个BIGINT字段没有任何问题 但是,当我在安装在自己计算机上的mysql中创建相同的表时,大的数字存储为2147483647,这是INT最大值 你知道为什么会这样吗 这是桌子 CREATE TABLE inPxUtBI_follow_data_tokens ( id int(20) unsigned NOT NULL, screen_name varchar(15) NOT NULL, token tinytext,

我在wordpress中有一个mysql数据库表,在其中声明一个BIGINT字段没有任何问题

但是,当我在安装在自己计算机上的mysql中创建相同的表时,大的数字存储为2147483647,这是INT最大值

你知道为什么会这样吗

这是桌子

CREATE TABLE inPxUtBI_follow_data_tokens (
  id int(20) unsigned NOT NULL,
  screen_name varchar(15) NOT NULL,
  token tinytext,
  secret tinytext,
  time_data_cursor datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  friends_cursor bigint(20) NOT NULL DEFAULT -1,
  followers_cursor bigint(20) NOT NULL DEFAULT -1,  
  datetime_created datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  time_data_cursor_index smallint(10) unsigned NOT NULL,
  PRIMARY KEY  (screen_name)
) ;
编辑:版本信息

mysql> \s
--------------
C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe  Ver 14.14 Distrib 5.7.22,
 for Win64 (x86_64)

Connection id:          2
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.7.22-log MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    cp850
Conn.  characterset:    cp850
TCP port:               3306
Uptime:                 30 min 3 sec

Threads: 1  Questions: 7  Slow queries: 0  Opens: 109  Flush tables: 1  Open tab
les: 102  Queries per second avg: 0.003
--------------
编辑:数据信息

这里是更新sql

update inPxUtBI_follow_data_tokens set followers_cursor = %d WHERE screen_name = '%s' ["1599757792260458963","xxx"]
update inPxUtBI_follow_data_tokens set friends_cursor = %d WHERE screen_name = '%s' ["1600189794255483463","xxx"]
这是更新的行

id,screen_name,token,secret,time_data_cursor,friends_cursor,followers_cursor,datetime_created,time_data_cursor_index
111,xxx,yyy,zzz,"2018-05-13 15:37:06",2147483647,2147483647,"2018-05-13 11:59:57",9
编辑:php代码

public static function setUserCursor($table, $field, $screen_name, $next_cursor) {
        flog(DEBUG, 'setUserCursor', $next_cursor);
        $update_count = 0;
        if ($next_cursor > 0) {
            global $wpdb;
            $sql = "update $table set $field = %d WHERE screen_name = '%s'";
            $sqldata = array($next_cursor, $screen_name);
            flog(DEBUG, 'setUserCursor', $sql . ' ' . json_encode($sqldata));

            $update_count = $wpdb->query($wpdb->prepare($sql, $sqldata));
        }
        return $update_count;
    }
编辑:@Progman的建议引发了一些奇怪的事情

在我的本地机器上

update inPxUtBI_follow_data_tokens set friends_cursor = %d WHERE screen_name = '%s' ["1557868487712412145","xxx"]
update inPxUtBI_follow_data_tokens set friends_cursor = 2147483647 WHERE screen_name = 'xxx'
但在我得到的远程服务器上

update inPxUtBI_follow_data_tokens set friends_cursor = %d WHERE screen_name = '%s' [1600189862942848368,"xxx"]
update inPxUtBI_follow_data_tokens set friends_cursor = 1600189862942848368 WHERE screen_name = 'xxx'
请注意第一行值“1557868487712412145”周围的引号

我已经把事情固定在这个函数上,在这个函数中检索json数据

function getFollowersIDs($user, $count, $cursor) {
    $url = $this->api . '1.1/followers/ids.json';
    $getfield = '?screen_name=' . $user . '&skip_status=1&count=' . $count . '&cursor=' . $cursor;
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($this->settings);
    $data = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    $rtn = json_decode($data, true, 512, JSON_BIGINT_AS_STRING);
    flog(VERBOSE, 'getFollowersIDs', $data);
    flog(DEBUG, 'getFollowersIDs', 'CURSOR: ' . json_encode(array($rtn['next_cursor'])));
    flog(DEBUG, 'getFollowersIDs', is_string($rtn['next_cursor']) ? $rtn['next_cursor'] . ' IS string' : $rtn['next_cursor'] . ' IS NOT string');

    return $rtn;
}
这些日志分别用于本地和远程

[getFollowersIDs] {"ids":[1492183206,913536285461147649,825717050538618880,961964711720910848,591132453,248777189,232207153,400934967,77967828,443634207],"next_cursor":1600147168522111920,"next_cursor_str":"1600147168522111920","previous_cursor":0,"previous_cursor_str":"0"}
[getFollowersIDs] CURSOR: ["1600147168522111920"]
[getFollowersIDs] 1600147168522111920 IS string


那么,为什么json_decode在一台机器上返回字符串,在另一台机器上返回bigint呢?

似乎您的本地机器使用4字节整数(32或64位PHP),而远程机器使用8字节整数(64位PHP)。整数的大小定义了BIGINT的大小:

如您所见,值
160014716852111920
不能放入4字节整数中,因此转换为字符串

现在,我不知道
wpdb::prepare
的底层实现,但显然它会尝试将
%d
转换为平台特定的整数,将
1600147168521111920
截断为
2147483647

echo sprintf("%d", "1600147168522111920");
// 2147483647

解决方案是将
%d
更改为
%s
。但在执行此操作之前,请确保所讨论的值看起来像一个有效的大整数。

似乎您的本地计算机使用4字节整数(32或64位PHP),而远程计算机使用8字节整数(64位PHP)。整数的大小定义了BIGINT的大小:

如您所见,值
160014716852111920
不能放入4字节整数中,因此转换为字符串

现在,我不知道
wpdb::prepare
的底层实现,但显然它会尝试将
%d
转换为平台特定的整数,将
1600147168521111920
截断为
2147483647

echo sprintf("%d", "1600147168522111920");
// 2147483647

解决方案是将
%d
更改为
%s
。但在此之前,请确保所讨论的值看起来像一个有效的大整数。

经过大量调查,我发现我的本地php是32位的

安装64位php解决了这个问题

那么有了这个数据,

[{"ids":[59150726,901375444934635520,385097832,331067377,194220828,540223123,2746743156,2271848935,819196471845253121,963324881906511877],"next_cursor":1597756074201108094,"next_cursor_str":"1597756074201108094","previous_cursor":-1597922052519508811,"previous_cursor_str":"-1597922052519508811"}]
这个代码

echo 'CURSOR: ' . json_encode(array($rtn[0]['next_cursor']))."\n";
生成此结果(值周围没有引号)

光标:[1597756074201108094]

我认为不同版本之间存在着一个相当模糊和误导性的差异


感谢@Progman带领我达成决议

经过多次调查,我发现我的本地php是32位的

安装64位php解决了这个问题

那么有了这个数据,

[{"ids":[59150726,901375444934635520,385097832,331067377,194220828,540223123,2746743156,2271848935,819196471845253121,963324881906511877],"next_cursor":1597756074201108094,"next_cursor_str":"1597756074201108094","previous_cursor":-1597922052519508811,"previous_cursor_str":"-1597922052519508811"}]
这个代码

echo 'CURSOR: ' . json_encode(array($rtn[0]['next_cursor']))."\n";
生成此结果(值周围没有引号)

光标:[1597756074201108094]

我认为不同版本之间存在着一个相当模糊和误导性的差异


感谢@Progman带领我达成决议

您的wordpress和您的计算机有哪个mysql版本和操作系统?您的计算机是否运行32位mysql可执行文件?我在windows 7上。MySql是在“C:\Program Files\MySql\MySql Server 5.7\bin”下运行的,这是否意味着它是64位的?windows 7 64位编辑,添加了版本信息,表示64位您对wordpress和您的计算机有哪个MySql版本和操作系统?您的计算机是运行32位MySql可执行文件吗?我在windows 7上。MySql在“C:\Program Files\MySql\MySql Server 5.7\bin”下运行,这是否意味着它是64位的?windows 7 64位编辑,添加了版本信息,表示64位