Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting query issue in join query

Tags:

php

mysqli

I am facing issue in SQL query and need some help.

I am newbie in Php and sql. So any help would be aprreciated.

I have the following Sql query and tries.

 $insert_on_duplicate_update_query = "INSERT INTO test (`store_client_id`,`customer_id`,`first_name`,`last_name`,`email`,`created_on`,`updated_on`,dob) VALUES('1','123','abc','xyz','[email protected]','2018-10-12 00:00:02','2018-10-12 00:00:02','NULL') ON DUPLICATE KEY UPDATE `store_client_id`='1',`customer_id`='123',`first_name`='abc',`last_name`='xyz',`email`='[email protected]',`updated_on`='2018-10-12 00:00:02',dob='null';";

  $insert_on_duplicate_update_query = str_replace(array("'NULL'","'null'"), null, $insert_on_duplicate_update_query);


 echo $insert_on_duplicate_update_query;

So here i want to replace 'NULL' to NULL in the follow place -

 VALUES('1','123','abc','xyz','[email protected]','2018-10-12 00:00:02','2018-10-12 00:00:02','NULL')
like image 598
uttam_devani Avatar asked Oct 12 '18 06:10

uttam_devani


People also ask

What are some performance issues with using joins?

Using lots of joins can slow down retrieval performance (though with proper indexing, the penalty is often a lot less than people think -- measure first). However, people tend to forget that removing the joins often means 'denormalizing' the data, which then incurs costs when the data must be modified.

Does join affect query performance?

Join order in SQL2008R2 server does unquestionably affect query performance, particularly in queries where there are a large number of table joins with where clauses applied against multiple tables. Although the join order is changed in optimisation, the optimiser does't try all possible join orders.

Why do joins slow down queries?

Joins: If your query joins two tables in a way that substantially increases the row count of the result set, your query is likely to be slow. There's an example of this in the subqueries lesson. Aggregations: Combining multiple rows to produce a result requires more computation than simply retrieving those rows.


2 Answers

Just need to change second parameter in str_replace function as bellow.

`$str = "abc = 'NULL'";
$a = str_replace("'NULL'", 'NULL', $str);
echo ($a);`

Second parameter with '' quotes.

like image 185
tejash patel Avatar answered Oct 25 '22 21:10

tejash patel


You need to change in str_replace() function on second line.

It should be as below.

$insert_on_duplicate_update_query = str_replace(array("'NULL'","'null'"), 'null', $insert_on_duplicate_update_query);

Hope it make sense

like image 24
Sachin Sarola Avatar answered Oct 25 '22 23:10

Sachin Sarola