Ok, I have such script
#!/bin/bash
keyOrPass=$1
intercom=$2
flat=$3
number=$4
mysql -ulogin -ppass db_name -e "select cli.codeGuestEmail, cli.codePrivateEmail, cliKey.rf_id, cliKey.emailNotification from mbus_clients as cli join mbusClientKeys as cliKey on cliKey.id_client=cli.id WHERE cli.flat=${flat} and cli.domophone=${intercom};";
php -q sendNotifications.php
It works fine, but I should pass some result fields from select into php arguments. Any ideas how to do it?
OUTPUT:
+----------------+------------------+------------+-------------------+
| codeGuestEmail | codePrivateEmail | rf_id | emailNotification |
+----------------+------------------+------------+-------------------+
| 1 | 0 | 2774490192 | 0 |
| 1 | 0 | 2774490193 | 0 |
| 1 | 0 | 2774490194 | 0 |
| 1 | 0 | 2774490195 | 1 |
+----------------+------------------+------------+-------------------+
mysql is capable of generating output formatted differently. With the -B or --batch option, mysql produces the output with TAB as the column separator. The special characters in the fields are escaped (e.g. TAB is output as "\t") so you can use cut to extract fields.
Many times in cases like this it's helpful to use the -N or --skip-column-names option as well, in order to remove column names from the output.
Related
I have one system (Symfony 5, symfony/messenger) sending data to another (Symfony 3.4, enqueue/enqueue-bundle 0.9) using a rabbitmq queue.
The data is used to create entities (stored in a MySql 8 database) that are executed within a transaction in case of a failure, to return the Database to the initial state.
My code is something like this (on the Symfony 3.4 side where the error is):
function runInsideTx(callable $fn)
{
$this->em->getConnection()->beginTransaction();
try {
$resp = $fn();
$this->em->flush();
$this->em->getConnection()->commit();
return $resp;
} catch (Exception $ex) {
$this->em->getConnection()->rollBack();
throw $ex;
}
}
And inside runInsideTx I have code like
$this->functions->runInsideTx(function () use ($message) {
$entity = new SomeEntity();
...
$this->em->persist($entity);
$this->em->flush();
})
Workers run inside a Docker container using supervisor:
[program:interop-manager_tasks-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /app/bin/console enqueue:transport:consume manager_tasks_processor manager_tasks_prod --message-limit=1 -vvv
autostart=true
autorestart=true
numprocs=2
redirect_stderr=true
stopwaitsecs=3600
stdout_logfile = /var/log/manager_tasks_worker_out.log
stderr_logfile = /var/log/manager_tasks_worker_err.log
user=application
environment=HOME="/home/application",USER="application"
Randomly the error General error: 2006 MySQL server has gone away occurs. Initially I had a MySql 5 Database and changed it to a MySql 8, which I am running inside a docker container with a single database.
Update
I have this error too:
Warning: Error while sending QUERY packet.
This happens sometimes. It could be that it sends the task to the queue three times and it fails the first two and the third it processes it without problems
I also added the following parameters when running the MySQl server:
command: --sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' --default-authentication-plugin=mysql_native_password --max-allowed-packet=1G --innodb_buffer_pool_size=512M --innodb_lock_wait_timeout=500
But the problem persists.
SHOW VARIABLES LIKE '%timeout%'
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 500 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| mysqlx_connect_timeout | 30 |
| mysqlx_idle_worker_thread_timeout | 60 |
| mysqlx_interactive_timeout | 28800 |
| mysqlx_port_open_timeout | 0 |
| mysqlx_read_timeout | 30 |
| mysqlx_wait_timeout | 28800 |
| mysqlx_write_timeout | 60 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| replica_net_timeout | 60 |
| rpl_stop_replica_timeout | 31536000 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 28800 |
+-----------------------------------+----------+
I'm developing an android application that uses PHP and makes requests with Mysql. Initially I tested all the features on the local server to then migrate it to an online server, in this case, Hostinger.
One of my PHP files returns the value of an array correctly on the local server, however, when using the same PHP file on the online server with the same database, the array only responds to TRUE when I run echo.
I tried doing the echo of each line and it is working perfectly, just not being able to associate the values with the keys in the array.
$result= mysqli_query($connect, $sql);
while ($patients= $result->fetch_assoc()){
echo $patients['group']; //prints OK
echo $patients['exercise_name']; //prints OK
echo $patients['use_exercise']; //prints OK
$insert[] = array("group" => $patients['group'],
"name" => $patients['exercise_name'],
"use" => $pacientes['use_exercise']
);
}
echo json_encode($insert); //prints TRUE
My mysql output from $result:
+------------------------------------------+
| group exercise_name use_exercise |
+------------------------------------------+
| Knee Knee _1 1 |
| Knee Knee _2 1 |
| Knee Knee _3 0 |
| Knee Knee _4 0 |
| Knee Knee _5 0 |
| Shoulder Shoulder_1 1 |
| Shoulder Shoulder_2 0 |
| Shoulder Shoulder_3 0 |
| Shoulder Shoulder_4 0 |
| Shoulder Shoulder_5 0 |
| Ankle Ankle _1 1 |
| Ankle Ankle _2 0 |
| Ankle Ankle _3 0 |
+------------------------------------------+
The rest of the PHP code is really not relevant to this. I ended up getting this result from it. My only problem is passing everything to the array. I've tested with another PHP file and it printed how it was supposed to, so I don't know what is happening.
This is my first time using Box/Spout library. I am using WAMP server.
My question is the following:
require_once('./spout-master/src/Spout/Autoloader/autoload.php');
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
$filePath = 'test.xlsx';
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($filePath);
[X]
$writer->addRow(['a'], $style);
$writer->close();
(1)
When I am running above code, I get the following error message:
Warning: rmdir(C:\WINDOWS\TEMP/xlsx560f58d588ceb): Permission denied in
C:\wamp\www\1300.revenue.com.my\public_html\spoutmaster\src\Spout\Common\Helper\FileSystemHelper.php on line 113
What is the errors means and how should I modify it to prevent this error message appeared?
(2) I want to make expected output like below:
But I didn't know how to write it on [X] part. How to write it in order to get the expected output?
It looks like the default temp folder used to generate the XLSX file cannot be deleted. You can verify it by checking the permissions on C:\WINDOWS\TEMP/xlsx560f58d588ceb.
To solve this issue, you can either manually fix the permissions on the temp folder (C:\WINDOWS\TEMP) or use another temporary folder, as specified here: https://github.com/box/spout#using-custom-temporary-folder
Regarding 2), there is no straightforward way to do this whith Spout. Spout does not support merging cells. The only thing you can do is:
| 1 | 2 | | 3 | |
|---|---|---|---|---|
| | A | B | A | B |
|---|---|---|---|---|
Or alternatively (if that makes more sense):
| 1 | 2 | 2 | 3 | 3 |
|---|---|---|---|---|
| 1 | A | B | A | B |
|---|---|---|---|---|
Either way, you'll have to format the rows as shown above: [[1,2,'',3',''], ['', 'A','B','A','B']] or [[1,2,2,3,3], [1, 'A','B','A','B']]
I am trying to fetch data from the roblox website using file_get_contents. I am trying to access the find a user page: http://www.roblox.com/search/users?keyword=
When I request the page I give 1 get parameter called username=[name]. However as soon as I try to load up the page no result is given back.
I tried file_get_contents, domdocument, curl. Nothing worked. I don't know what to do anymore.
<?php
$User = $_GET["username"];
$Result = file_get_contents("http://www.roblox.com/search/users?keyword=".$User);
var_dump($Result);
?>
I'm not getting any errors. Just chrome connection timeout errors.
Try this with firebug (dev tools) open: http://codepad.viper-7.com/fbEOPp
Would have to dig in a bit more to see what obfuscation is happening. At least one redirect in there. Might be looking at the agent or using other means. Maybe look if they offer an API or take a look at their site terms and conditions.
Source shows...
_______ _________ _____ ______ _
/ _____ \ |____ ____| / ___ \ | ____ \ | |
/ / \_\ | | / / \ \ | | \ \ | |
| | | | / / \ \ | | | | | |
\ \______ | | | | | | | |___/ / | |
\______ \ | | | | | | | ____/ | |
\ \ | | | | | | | | | |
_ | | | | \ \ / / | | |_|
\ \_____/ / | | \ \___/ / | | _
\_______/ |_| \_____/ |_| |_|
Keep your account safe! Do not paste any text here.
If someone is asking you to paste text here then you're
giving someone access to your account, your gear, and
your ROBUX.
To learn more about keeping your account safe you can go to
https://en.help.roblox.com/hc/en-us/articles/203313380-Account-Security-Theft-Keeping-your-Account-Safe-
(hmm, seems they spit that out always with every request - though it was specific to how we were trying things)
Still, might be the site does not like you scraping their (your?) content and is actively trying to thwart your attempts.
Here is a screenshot of what I get from file_get_contents after a 15 second wait...
Just chrome connection timeout errors.
That suggests that your php script isn't failing but stalling. Could be the http request; so, let's try it with a shorter timeout:
<?php
ini_set('display_errors', true);
error_reporting(-1);
$User = $_GET["username"];
$ctx = stream_context_create(array('http'=>array(
'timeout'=>3.0
)));
$Result = file_get_contents(
"http://www.roblox.com/search/users?keyword=".$User,
false,
$ctx
);
var_dump($Result);
?>
I have a problem with MySql
I have a table with parsed informations from websites. A strange string interpretation appear:
the query
select id, address from pagesjaunes_test where address = substr(address,1,length(address)-1)
return a set of values instead of none
at beginning I executed functions as:
address = replace(address, '\n', '')
address = replace(address, '\t', '')
address = replace(address, '\r', '')
address = replace(address, '\r\n', '')
address = trim(address)
but the problem still persist.
Values of field 'address' have some french chars , but the query returned also values that contains only alfanumeric english chars.
Another test: I tried to check the length of strings and ... the strlen() from PHP and LENGTH() from MYSQL display different results! Somewhere difference is by 2 chars, somewhere by 1 character without a specific "rule".
Visual I can't see any space or tabs or something else.
After I modified an address manualy(I deleted all string and I wrote it again), the problem is solved, but I have ~ 6000 values, so this is not a solution :)
What can be the problem?
I suppose that strings can have something as an "empty char", but how to detect and remove it?
Thanks
P.S.
the problem is not just length. I need to join this table with other one and using a condition that check if values from fields 'address' are equals. Even if the fields have the same collation and tables have the same collation, query returns that no addresses match
E.g.
For query:
SELECT p.address,char_length(p.address) , r.address, char_length(r.address)
FROM `pagesjaunes_test` p
LEFT JOIN restaurants r on p.name=r.name
WHERE
p.postal_code=r.postal_code
and p.address!=r.address
and p.phone=''
and p.cuisines=''
LIMIT 10
So: p.address!=r.address
The result is:
+-------------------------------------+------------------------+--------------------------+------------------------+
| address | char_length(p.address) | address | char_length(r.address) |
+-------------------------------------+------------------------+--------------------------+------------------------+
| Dupin Marc13 quai Grands Augustins | 34 | 13 quai Grands Augustins | 24 |
| 39 r Montpensier | 16 | 39 r Montpensier | 16 |
| 8 r Lord Byron | 14 | 3 r Balzac | 10 |
| 162 r Vaugirard | 15 | 162 r Vaugirard | 15 |
| 32 r Goutte d'Or | 16 | 32 r Goutte d'Or | 16 |
| 2 r Casimir Périer | 18 | 2 r Casimir Périer | 18 |
| 20 r Saussier Leroy | 19 | 20 r Saussier Leroy | 19 |
| Senes Douglas22 r Greneta | 25 | 22 r Greneta | 12 |
| Ngov Ly Mey44 r Tolbiac | 23 | 44 r Tolbiac | 12 |
| 33 r N-D de Nazareth | 20 | 33 r N-D de Nazareth | 20 |
+-------------------------------------+------------------------+--------------------------+------------------------+
As you see, "162 r Vaugirard", "20 r Saussier Leroy" contains only ASCII chars, have the same length but aren't equals!
Maybe have a look at the encoding of the mysql text fields - UTF8 encodes most of its characters with 2 bytes - only a small subset of UTF8 (ASCII characters for example) get encoded with one byte.
MySQL knows UTF8 and counts right.
PHP text functions aren't UTF8 aware and count the bytes itself.
So if PHP counts more than MYSQL, this is probably the cause and you could have a look at utf8decode.
br from Salzburg!
The official documentation says:
Returns the length of the string str, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
So, use CHAR_LENGTH instead :)
select id, address from pagesjaunes_test
where address = substr(address, 1, char_length(address) - 1)
Finally, I found the problem. After changed collation to ascii_general_ci all non-ascii chars was transformed to "?". Some spaces also was replaced with "?". After check initial values, function ORD() from MySQL returned 160 (instead of 32) for these spaces. So,
UPDATE pagesjaunes_test SET address = TRIM(REPLACE(REPLACE(address, CHAR(160), ' '), ' ',' ')
resolved my question.