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));
Related
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.
i want to connect to sqlserver
i have this
php -v
PHP 7.2.14-1+0~20190113100742.14+stretch~1.gbpd83c69 (cli) (built: Jan 13
2019 10:07:43) ( NTS )Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.14-1+0~20190113100742.14+stretch~1.gbpd83c69, Copyright (c) 1999-2018, by Zend Technologies
where i used sqlser
$conn = new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx;Database=xxxx', 'user', 'pass');
i have this problem
SQLSTATE[01000]: [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1' : file not found
but this file is exite in path
and when i used DBLIB
$conn = new PDO( "dblib:host=$hostname;dbname=$dbname;", $username, $pw);
after many secand (2 minutes) i have this problem
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
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?
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 );
?>
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.