What is different binding and duration of mysql query? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have log from laravel that showing the binding time and duration time of query execution:
select * from `yg_product_detail` where `product_id` = '5551973459553' and `yg_product_detail`.`deleted_at` is null limit 1
Metadata
Bindings 0. 55197345953
Hints Use SELECT * only if you need all columns from table
LIMIT without ORDER BY causes non-deterministic results, depending on the query exection plan
Duration 26.8s
And as seen above, my duration time is too long, but I need to make sure, is the duration time the real time from mysql query? or process logic between another query?
because when I try to run those query to mysql, its run fast.
Thank you

Bindings are values inserted into your SQL query. The execution time displayed on the upper right corner is the actual round-trip time the SQL query took to execute (i.e. the time elapsed between sending the query to the DBMS and the DBMS returning the result as well as parsing the result into models).
If you have an Eloquent query like this:
User::where('name', 'like', '%john%')
->orderBy('age')
->get();
Then it will be converted to a prepared SQL statement like this:
select *
from `users`
where `name` like ?
order by `age`
where the ? gets replaced by a binding, in this case '%john%'. In your case, the binding is the product_id which you attempted to cross out in the query but left in the query explanation table.

Related

sql statement in PHP doesn't update the Database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
When I put a number myself the database gets updated to Success but when I try to access the same number from $_POST It complete the transaction but doesn't affect the rows even thought it's using the same number.
Example of a query that works perfectly and updates the database
$sql = "UPDATE `transactions` SET `status` ='Success' WHERE `transactions`.`txn_id` = 65765756";
Example of a query that doesn't work
$sql = "UPDATE `transactions` SET `status` ='Success' WHERE `transactions`.`txn_id` = ".$_POST['m_payment_id'];
First, check what's in the value, and make sure it is the same as what you are manually entering.
var_dump($_POST['m_payment_id'])
Second, the code without any other checks is a SQL injection vulnerability.
You could convert the value into an integer to protect against this, e.g. intval($_POST['m_payment_id'])
Ideally though, you would be using bindings.

Using PHP?= to navigate between pages [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am able to navigation between a php page using ID but not using project name. Can you only use an number and not characters?
Works
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE id=$id";
'.$row['project'].'
page url: https://example.com/project.php?id=1
Doesn't work
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE project=$project";
'.$row['project'].'
page url: https://example.com/project.php?project=Test
Thanks for the help!
MySQL uses single or double quotes for strings. Your second query puts string to a query, resulting in invalid query.
This is not a valid SQL query:
SELECT `name` FROM `cats` WHERE `breed` = ordinary cat
But this is:
SELECT `name` FROM `cats` WHERE `breed` = 'ordinary cat'
Of note, be careful with using any input (including query string) in your query like you did. You should use prepared statement instead to safely escape that string for your query.

Select from database only values not seen before [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Let's say that I have a database with this data stored:
Email-Link-Link2
1E#231-Example1-Example2
1E#231-Example3-Example4
How can I select all of this value with a PDO query excluding those seen before, so in this case 1E#231,will select only one time.
If understand what you said, this is your answer:
Connexion to data base with PDO
<?php
//CONNEXION TO DATA BASE WITH PDO...
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$base = new PDO('mysql:host=localhost;dbname=your_data_base', 'the_user', 'Your_password', $pdo_options);
//end of connexion to data_base
;?>
NOW getting data from data base with not duplication(you can use sql function DISTINCT
<?php
$sc=$base->query("SELECT DISTINCT Email FROM table_where_data_stored");
while($data_distinct =$sc->fetch()){
//your data will be displayed here
;}
;?>
May this help you!!
To evade double selection commonly one use the DISTINCT statement, like this:
SELECT DISTINCT *
FROM myTable
But the best way to evade double-selection is to evade redundant entries to the database. As far as I understand the two entries in your database the second one is an update, and you don't want to overwrite the previous entry. This is a well known problem, and commonly solved like this:
There is a certain date from when on the new eMail should be used, so add a field "valid_from" and add this WHERE statement to your query:
WHERE valid_from > GETDATE()
GETDATE() returns a datetime, therefore it's enough to select "greater than".

Is there a limit on the number of rows I can update via an IN clause of a MySQL query? [duplicate]

This question already has answers here:
MySQL number of items within "in clause"
(5 answers)
Closed 7 years ago.
Is there a limit on the number of rows that I can update in a single query using an IN clause? For example:
mysql_query("UPDATE `table` SET `row`=1 WHERE `id` IN(1,2,3,4,5,6,7,8....5000)");
Could I update all 5000 rows at once? Or does MySQL have a limit on the number of items in an IN clause?
Please note: I want to know if there is a limit of updates in one single query where MySQL would say something like "maximum number of IN clause entries exceeded". That is, I am inquiring about a possible limit other than the "maximum packet size" setting in MySQL.
According to the MySQL documentation for the IN function, there is no hard limit on the number of values that can be specified in such a list. The documentation specifically says:
The number of values in the IN list is only limited by the max_allowed_packet value.
However, there is another question here that discusses whether or not there might be a practical limit beyond which a temporary table containing the values might yield better performance when used with a JOIN or an IN(subquery) in the WHERE clause.

How to make this MySQL query execute faster? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
SELECT * FROM (`collection_series`)
JOIN `datadatexnumericy` ON
`collection_series`.`series_id` = `datadatexnumericy`.`series_id`
JOIN `saved_users_chart` ON `collection_series`.`collection_id` =
`saved_users_chart`.`chart_id`
WHERE `saved_users_chart`.`chart_id` = '265'
AND `saved_users_chart`.`id` = '6' AND `datadatexnumericy`.`x` >=
'1973-09-30' AND `datadatexnumericy`.`x` <= '2014-06-30' AND
`datadatexnumericy`.`series_id` != '43538'
AND `datadatexnumericy`.`series_id` != '43541'
GROUP BY YEAR(datadatexnumericy.x)
This is my SQL query and result of this query I am getting from AJAX response this query is working fine but I am getting response slow a bit I think the problem is in my SQL query.
I want all matching records from collection_series and datadatexnumericy table and only matching row from saved_users_chart is there any possible way to optimize this query in more efficient way so that I can get ajax response faster.
In my opinion your query is already optimized. You should test the result of the query in an SQL server to see response time of SQL server and then compare with the time you actualy receive the response back from server.
If is not necesary to extract all the columns from each table, then manualy enter the column names instead of *. By doing this the response received from server will be certainly smaller, therefore it will be faster.

Categories