Timestamp value not same in server and local after dumping in laravel - php

I have one table with timestamp including milliseconds value so I just dd in my file to check whether it is working fine or not
so in my local machine when I dumped data i got this
array:1218 [
0 => {#735
+"Id": 1
+"AverageSpeed": null
+"OverSpeedDuration": 0
+"StartCheckPointTimeStamp": "2020-05-07 05:05:30.000"
+"EndCheckPointTimeStamp": "2020-05-07 05:05:30.000"
+"Status": 1
+"TimeStamp": "2020-05-07 05:05:31"
+"CurrentSpeed": 0
+"CurrentAccuracy": 0
+"CurrentDirection": 0
+"StartCheckPointId": 801
+"EndCheckPointId": 801
+"ResultId": 1
+"MarshalId": null
}
and when i did same thing in server file I got this
array:1218 [
0 => {#741
+"Id": 1
+"AverageSpeed": null
+"OverSpeedDuration": 0
+"StartCheckPointTimeStamp": "2020-05-07 05:05:30"
+"EndCheckPointTimeStamp": "2020-05-07 05:05:30"
+"Status": 1
+"TimeStamp": "2020-05-07 05:05:31"
+"CurrentSpeed": 0
+"CurrentAccuracy": 0
+"CurrentDirection": 0
+"StartCheckPointId": 801
+"EndCheckPointId": 801
+"ResultId": 1
+"MarshalId": null
now the problem is in my local machine and also in server the database I am using is same
and startCheckPointTimestamp column has dataType timestamp(3)
but I am not sure why my local machine dumps right value while server code dumps timestamp without milliseconds
Only the difference I am assuming is php version i.e
in my local machine php 7.4 and in my server php 7.2
so any hints why this is happening?

Related

PDO Insert not accepting "true" or "false", but only 0 and 1

After introducing phinx as a database migration tool, I am no longer able to use true and false through PDO's execute statement. Whenever I do, I get the following error:
PHP Warning: PDOStatement::execute(): SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column 'my_db'.'my_table'.'my_column' at row 1...
My table has the following schema (shorted):
| Field | Type | Null | Key | Default | Extra |
+-------------------------------+--------------+------+-----+---------+----------------+
| my_column | tinyint(1) | NO | | NULL | |
+-------------------------------+--------------+------+-----+---------+----------------+
I am using the following code (shorted):
$stmt = $this->pdo->prepare("INSERT INTO `$table` (`my_column`) VALUES (:mycolumn)");
$stmt->execute([
'my_column' => false
]);
The column is created by the migration script with:
->addColumn('my_column', 'boolean', [
'null' => false,
'after' => 'another_column',
])
The strange thing is, that I have no problems with using true and false in manual sql statements through phpMyAdmin.
you can use PDO::PARAM_BOOL in PDO
$stmt->bindValue(':myColumn', false, PDO::PARAM_BOOL);
This happened to me when i use macOS,
i was building my website from Windows 10, and works fine.
After using macOS i had to change the variables to 1 or 0
I hope you fixed it.
A solution to that problem is to set sql_mode = '' globally.
Run this query in you DB and check if it fixes the issue:
set GLOBAL sql_mode = "";
You can read up on Server SQL Modes here
P.S. you have to run that query everytime you restart your mysql server. To overcome this you have to set it in mysql config which you can look it up if required.
Your field type is tinyint(1). so it supports only values from 0-9 . Change to to varchar, text, char etc to accept true/false string.
But i strongly suggest you to use bool datatype. Then use 0 or 1 as true or false. There is no point in writing string (true/false) values for boolean operations. Using 0 or 1 will save you from lot of troubles in the future.

Communicate with child process bidirectionally over STDIO

I am trying to communicate with the Stockfish chess engine from a PHP script. For that I am using the UCI protocol, so I will need to send commands line by line. For example, this is what I would normally enter on the Windows Command Prompt:
Stockfish.exe
position startpos
go depth 16
Stockfish.exe is the 64-bit version of the Stockfish chess engine.
I failed to do it using exec(). Here is how I attempted it:
exec("stockfish.exe\nposition startpos\ngo depth 16");
The engine runs, but the commands are not executed, so I get:
Stockfish 10 64 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
where I should get something like:
info depth 1 seldepth 1 multipv 1 score cp 116 nodes 20 nps 10000 tbhits 0 time 2 pv e2e4
info depth 2 seldepth 2 multipv 1 score cp 112 nodes 54 nps 27000 tbhits 0 time 2 pv e2e4 b7b6
info depth 3 seldepth 3 multipv 1 score cp 148 nodes 136 nps 45333 tbhits 0 time 3 pv d2d4 d7d6 e2e4
info depth 4 seldepth 4 multipv 1 score cp 137 nodes 247 nps 61750 tbhits 0 time 4 pv d2d4 e7e6 e2e4 c7c6
bestmove d2d4 ponder e7e6
I've read many threads on related issues, but couldn't find a workaround. Is there any way to accomplish this?

How to parse tab-delimited file into mysql database

I was tasked with parsing a tab-delimited file and inserting the values into the database. Find a selection of the tab-delimited file below.
"030-36-2" 0 0 14 "P"
"030-38-2" 0 0 14 "S"
"030-40-2" 0 0 14 "S"
"031-2-2" 1 0 "O"
"031-3-2" 4 0 "O"
"032-36-26" 0 0 14 "S"
"032-38-26" 0 0 14 "S"
"032-40-26" 0 0 14 "S"
"070-140-161" 0 0 14 "S"
"070-140-162" 2 0 "D"
"070-83-161" 0 0 14 "S"
I'm using fgetcsv with my delimiter set to a tab (9) but upon executing the code I am only getting a small percentage of total values inserted into the database.
This is my code:
if(($handle = fopen("mytabdelimitedfile.txt","r"))!==FALSE){
fgetcsv($handle, 0,chr(9));
while(($data = fgetcsv($handle,1000,chr(9)))!==FALSE){
print_r($data[0]);
$result = mysql_query("INSERT INTO $table (col1,col2,col3,col4,col5) VALUES('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')");
}
}
The first 4 records are not inserted but it starts with "031-3-2", then skips down to "070-140-162". I fear the result may have to do with some values missing but I cannot seem to discern a pattern.
Does anyone have any insight regarding this? Does the issue have to do with some values missing? Is there any workaround? (I don't have any control over source data)
Also another note: when I use Excel => import data from text => tab-delimited, the results are perfect. But of course I cannot use Excel as the data is updated on an hourly basis. Please, any point in the right direction would be GREATLY appreciated.
Like VMai saide, use LOAD DATA INFILE
LOAD DATA LOCAL INFILE 'mytabdelimitedfile.txt'
INTO TABLE table_name
FIELDS
TERMINATED BY '\t'
OPTIONALLY ENCLOSED BY '"'
(col1,col2,col3,col4,col5)
Also, I really hope those aren't your actual column names.
And don't rely on Excel as an example for anything. It hasn't handled CSV in a sane manner since at least 2007.

How add array to redis?

participants
I use REDIS database and use PHP client http://rediska.geometria-lab.net/documentation/
Here i found type Sorted sets and try create users list for current user.
My code is:
$sortedSet = new Rediska_Key_SortedSet('userslist'); // use collaction userslist
$sortedSet[1] = array('name' => 'Max');
$sortedSet[1] = array('name' => 'Vasile');
As I understand userslist indicates the name of the collection, and the number 1 in $ sortedSet [1] key. Then, in the console through the client redis-cli write:
127.0.0.1:6379> SMEMBERS 1: userslist
(empty list or set)
and get a empty blank ... prompt, what am I doing wrong? May be my concept is wrong?
The sorted set commands is prefixed with Z.
http://redis.io/commands#sorted_set
Try:
ZRANGE userslist 0 -1
SMEMBERS is set not SORTED SETS for sorted sets USE ZSETS
ZADD myzset 3 "two"
ZRANGE myzset 0 -1 WITHSCORES
ZADD expects 3 parameters key, score and member, You are not providing it in your code
ZADD myzset 1 "one"
ZADD myzset 1 "uno"
You will have to use ZRANGE to get the range from sorted sets
ZRANGE myzset 0 -1 // This will give all values in SETS
I do not know how the PHP library works but it seems you have overwriting the members
$sortedSet[1] = array('name' => 'Max');
$sortedSet[1] = array('name' => 'Vasile');
Use Monitor command on redis-cli it will help you to analyze which command redis is processing. So start redis-cli and type monitor and then run your script and check in redis-cli which command it is firing
redis-cli monitor
TIP: Try not to write any code until you understand how things works. E.g. In this case try to understand the difference between SETS and ZSETS

php odbc double excecutions bug

I am using Windows Server with MSSQL Server 2008, and a ODBC connection to WAMP on a seperate Windows Server.
Using PHP to execute database queries, and when I run INSERT queries I get two identical rows (with unique identifier as the only thing seperating them).
I have checked multiple times that it's not double posting, so it must be executing the code twice, or sending it twice, the problem is not on the PHP side, that's for sure.
For example, I run this code:
$sql = "INSERT INTO mytable(aboutPerson, fromPerson, comment)
VALUES(1,5, 'hello')";
//.. create connection to db
odbc_exec($sql);
//.. close connection to db
Out of that I get two identical rows in the table. This occurs on several tables.
Why does this occur and how can I stop it from happening? Is it a known bug in connecting WAMP to Microsoft SQL Server with ODBC?
BTW, I don't have the option of switching systems.
Any help would be very appreciated, thanks!
Edit-
An actual example by request.
$SQL = "INSERT INTO billboard (toPersonId, toGroupClass, toOfficeId, fromOfficeId,
fromType, fromId, header, msg, aboutPersonId, created, startMessageId,
fromPersonId, status, emailNote, smsNote)
VALUES (1, 0, 1, 1,
2, 1, 'cccccccccccccc', 'cccccccccccccccc', '', GETDATE(), 0,
1, 0, 0, 0)";
$resource = odbc_connect(database server url, username, password);
$statement = odbc_exec($SQL, $resource);
return odbc_free_result($statement);
I execute this code and I should get only 1 single row inserted into the table. Instead I get this, two identical rows (except for the first column, which is the primary key and is identity)
111 1 0 1 1 2 1 cccccccccccccc cccccccccccccccc 0 2012-10-10 12:56:27.773 0 1 0 0 0
110 1 0 1 1 2 1 cccccccccccccc cccccccccccccccc 0 2012-10-10 12:56:27.773 0 1 0 0 0

Categories