MongoDate toDateTime() function is not defined? - php

This is stumping me... I'm using the exact example from:
http://php.net/manual/en/mongodate.todatetime.php
but I'm getting:
PHP Fatal error: Call to undefined method MongoDate::toDateTime()
<?php
$d = new MongoDate(strtotime("2014-11-18 11:01:25"));
var_dump($d);
var_dump( $d->toDateTime() );
?>
The exact output I get is:
object(MongoDate)#1 (2) {
["sec"]=>
int(1416330085)
["usec"]=>
int(0)
}
PHP Fatal error: Call to undefined method MongoDate::toDateTime() in /xxx/testmongodate.php on line 5
PHP version:
$ php -v
PHP 5.5.9-1ubuntu4.9 (cli) (built: Apr 17 2015 11:44:57)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
PHP config:
$ php -i | grep mongo
/etc/php5/cli/conf.d/20-mongo.ini,
mongo
mongo.allow_empty_keys => 0 => 0
mongo.chunk_size => 262144 => 262144
mongo.cmd => $ => $
mongo.default_host => localhost => localhost
mongo.default_port => 27017 => 27017
mongo.is_master_interval => 15 => 15
mongo.long_as_object => 0 => 0
mongo.native_long => 0 => 0
mongo.ping_interval => 5 => 5
I have been successfully using this installation to insert into and read from an actual mongo database, but now I'm trying to work with MongoDate objects as they are read out of mongo, trying to format them for insert into another database... that is why I'm looking to use this method... but it doesn't seem to be found... ??
$ uname -a
Linux server1 3.13.0-52-generic #86-Ubuntu SMP Mon May 4 04:32:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

For anybody coming to this question late (as I did), the likely issue is that the PHP is using a different Mongo driver. There are currently 2 and the below code is for the legacy driver.
The solution with the legacy driver is to get the date from the Mongo Date using the PHP date function:
<?php
$d = new MongoDate(strtotime("2014-11-18 11:01:25"));
$newdate = date('Y-m-d H:m:s',$d->sec);
var_dump( $newdate );
?>

Related

Swoole sending check_worker_exit_status() log

I have a problem while using laravel with swoole on php 8.1.Some requests finished with HTTP 408 sometimes. Then when I looked at the log file, I saw the following error.
[2022-07-29 08:59:52 $28.0] WARNING Server::check_worker_exit_status(): worker(pid=49, id=4) abnormal exit, status=0, signal=9
then I watched all the processes with "strace" command. I saw the worker killed by manager process. Logs are bellow:
ps -aux
www 54 0.0 0.9 473088 39424 ? Sl 12:40 0:00 swoole_http_server: master process
www 65 0.0 0.5 401440 21036 ? S 12:40 0:00 swoole_http_server: manager process
www 1608 0.2 1.3 427668 52384 ? S 13:19 0:00 swoole_http_server: worker process
strace.log:
54 13:27:40.909415 kill(1608, 0) = 0
54 13:27:40.909598 kill(1608, SIGKILL) = 0
1608 13:27:40.943992 +++ killed by SIGKILL +++
65 13:27:40.944275 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=1608, si_uid=1111, si_status=SIGKILL, si_utime=3840, si_stime=1000} ---
65 13:27:40.944400 rt_sigreturn({mask=[]}) = 1608
I tryed a lot of things but not fixed this problem. How can i deal it?
php -v:
PHP 8.1.8 (cli) (built: Jul 11 2022 08:30:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.8, Copyright (c) Zend Technologies
with Zend OPcache v8.1.8, Copyright (c), by Zend Technologies
php --ri swoole
swoole
Swoole => enabled
Author => Swoole Team <team#swoole.com>
Version => 4.8.10
Built => Jul 6 2022 13:14:29
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
php artisan --version
Laravel Framework 9.21.3
uname -a
Linux 9968d896fe6c 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
gcc -v
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1)

yii2 use dblib driver SQLSTATE[HY000]: General error: 20018 Invalid object name t_user

I have use dblib driver in my project ,
but execute query exception
Database Exception – yii\db\Exception
SQLSTATE[HY000]: General error: 20018 Invalid object name 't_user'. [20018] (severity 16) [select top 10 * from t_user]
The SQL being executed was: select top 10 * from t_user
Error Info: Array
(
[0] => HY000
[1] => 20018
[2] => Invalid object name 't_user'. [20018] (severity 16) [select top 10 * from t_user]
[3] => -1
[4] => 16
)
↵
Caused by: PDOException
SQLSTATE[HY000]: General error: 20018 Invalid object name 't_user'. [20018] (severity 16) [select top 10 * from t_user]
If I use native PHP, it's OK
<?php
$dbh = new PDO("dblib:host=;dbname=","","");
$query = $dbh->prepare("SELECT top 1 * from t_user");
$query->execute();
while($row = $query->fetch()){
print_r($row);
}
I install freetds php_dblib
The configuration information
➜ www /usr/local/Cellar/freetds/1.1.40/bin/tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v1.1.40
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: yes
GnuTLS: no
MARS: yes
➜ www php -v
PHP 7.3.18 (cli) (built: May 29 2020 02:17:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.18, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
with Zend OPcache v7.3.18, Copyright (c) 1999-2018, by Zend Technologies
➜ www php -m | grep dblib
pdo_dblib
➜ www php --ri pdo_dblib
pdo_dblib
PDO Driver for FreeTDS/Sybase DB-lib => enabled
Flavour => freetds
the yii2 config [ use yii2 basic 2.0.x]
<?php
return [
'class' => 'yii\db\Connection', // yii connection
'dsn' => 'dblib:host=;database=', // this is dblib
'username' => '', // user name
'password' => '', // password
'charset' => 'utf8',
];
I don't know how to tackle this problem。
Ask for help, Daniel~
As already mentioned, "user" is a reserved word. Using reserved words as identifiers is a bad idea - and you really need to develop good habits not more bad ones.
You SHOULD change the name of your table so that it does not need to be delimited. Learn by by reading the documentation for regular identifiers. But you can use the following:
select <columns of interest> from dbo.[user] order by <whatever>:
Note the good habits - schema-qualify object names, specify the columns you need, apply an ORDER BY clause if needed.

php 5.6.13, PDO, connect to interbase fails (Debian GNU/Linux 7.7 (wheezy))

I can connect to my interbase using IBConsole using the same user/pass as I use in php
php --version
PHP 5.6.13-0+deb8u1 (cli) (built: Sep 7 2015 13:38:37)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
Installed interbase: apt-get install libapache2-mod-php5 php5-interbase
phpinfo() returns:
Firebird/InterBase Support: dynamic
Compile-time Client Library Version: Firebird API version 25
Run-time Client Library Version LI-V6.3.3.26778: Firebird 2.5
PDO drivers enabled: firebird, mysql
PDO_Firebird, PDO Driver for Firebird: enabled
Firebird driver for PDO: Ard Biesheuvel
php test 1:
$host = 'MYSRV1:C:\folder\dbhms.ib';
$username = 'dbuser';
$password= 'dbpassword';
$conStr = "firebird:dbname={$host};User={$username};Password={$password};Port=3050;";
$DB = new PDO($conStr);
result:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [335544472] Your user name and password are not defined. Ask your database administrator to set up a Firebird login.' in /home/tr/ibase/test.php:29
php test 2:
print_r(PDO::getAvailableDrivers());
result:
;Array
(
[0] => firebird
[1] => mysql
)
Php documentation for PDO::getAvailableDrivers on http://php.net/manual/en/pdo.getavailabledrivers.php:
print_r(PDO::getAvailableDrivers());
result:
Array
(
[0] => mysql
[1] => sqlite
)
I notice that there is a leading ';' in my test 2 (;Array ) but it should not cause any trouble
What am I missing?

PHP PDO FOUND_ROWS() returns 0

We use PDO connector on product environment and recently we facing a new issue. Somehow the mysql FOUND_ROWS() returns 0
I have also tried to run the SQL queries manually in mysql console but FOUND_ROWS() returns correct count in console.
What i found: PDO broken, mysqli works
Testing code:
<?php
$db = new PDO('mysql:host=dbhost;dbname=projectname;charset=utf8', 'projectname', '***');
print_r($db->query("SELECT SQL_CALC_FOUND_ROWS `id_sales_order` FROM `sales_order` WHERE RAND() > 0.8 LIMIT 0, 1")->fetchAll(PDO::FETCH_ASSOC));
print_r($db->query("SELECT FOUND_ROWS()")->fetchAll(PDO::FETCH_ASSOC));
$mysqli = new mysqli("dbhost", "projectname", "***", "projectname");
print_r($mysqli->query("SELECT SQL_CALC_FOUND_ROWS `id_sales_order` FROM `sales_order` WHERE RAND() > 0.8 LIMIT 0, 1")->fetch_assoc());
print_r($mysqli->query("SELECT FOUND_ROWS()")->fetch_assoc());
Results:
Array
(
[0] => Array
(
[id_sales_order] => 13
)
)
Array
(
[0] => Array
(
[FOUND_ROWS()] => 0
)
)
Array
(
[id_sales_order] => 7
)
Array
(
[FOUND_ROWS()] => 670336
)
Versions:
Mysql Server version: 5.6.21-70.0-log Percona Server (GPL), Release 70.0, Revision 688
PHP 5.4.33 (cli) (built: Sep 20 2014 16:20:03)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
MysqlI Support => enabled
Client API library version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $
PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $
I have had the same problem before however I fixed it by using fetch(PDO::FETCH_COLUMN).
print_r($conn->query("SELECT FOUND_ROWS()")->fetch(PDO::FETCH_COLUMN));

Finding Win CMD columns (gives result+error)

I have problem with following script:
$ exec('mode con /status', $tmp); print_r($tmp);
It runs the command and gives me result, but also I get every time error message too:
The system cannot find the path specified.
I just want get terminal window size $COLS x $ROWS
Used system: PHP 5.4 + Win7
Test results here:
C:\#home\Devel>C:\php\php.exe -v
PHP 5.4.13 (cli) (built: Mar 15 2013 02:05:59)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
C:\#home\Devel>C:\php\php.exe -r "exec('mode con /status', $tmp); print_r($tmp);"
The system cannot find the path specified.
Array
(
[0] =>
[1] => Status for device CON:
[2] => ----------------------
[3] => Lines: 1200
[4] => Columns: 160
[5] => Keyboard rate: 31
[6] => Keyboard delay: 0
[7] => Code page: 775
[8] =>
)
How can I get rid of this error message!?!
Thanks.

Categories