Use MySQL REPLACE Statement to Prevent Duplicate Data Insertion

varun
Updated on 22-Jun-2020 13:26:43

481 Views

We can use the REPLACE statement while inserting the data to prevent the insertion of duplicate data. If we will use the REPLACE command rather than the INSERT command then if the record is new, it is inserted just as with INSERT else if it is a duplicate, the new record replaces the old one.SyntaxREPLACE INTO table_name(…)Here,  table_name is the name of the table in which we want to insert the values.ExampleIn this example we will insert the data with the help of REPLACE statement as follows −mysql> REPLACE INTO person_tbl (last_name, first_name)     -> VALUES( 'Ajay', 'Kumar'); Query OK, ... Read More

Scope of Variables in C#

Samual Sam
Updated on 22-Jun-2020 13:25:45

1K+ Views

The scope of a variable is a region of code that indicates where the variables are being accessed.For a variable, it has the following levels −Method LevelVariable declared inside a method is a local variable.Class LevelVariable declared inside a class is a local variable are class member variables.Let us see an example of scope of variables −Example Live Demousing System; namespace Demo {    class Program {       public int Divide(int num1, int num2) {          // local variable in a method          int result;          result = num1 ... Read More

C# Program to Determine if Two Words are Anagrams of Each Other

karthikeya Boyini
Updated on 22-Jun-2020 13:25:04

9K+ Views

For anagram, another string would have the same characters present in the first string, but the order of characters can be different.Here, we are checking the following two strings −string str1 = "heater"; string str2 = "reheat";Convert both the strings into character array −char[] ch1 = str1.ToLower().ToCharArray(); char[] ch2 = str2.ToLower().ToCharArray();Now, sort them −Array.Sort(ch1); Array.Sort(ch2);After sorting, convert them to strings as shown in the following code −Example Live Demousing System; public class Demo {    public static void Main () {       string str1 = "heater";       string str2 = "reheat";       char[] ch1 ... Read More

Convert Array to Ordinary List in C#

Samual Sam
Updated on 22-Jun-2020 13:24:36

122 Views

Set an array −int[] arr = { 23, 66, 96, 110 };Now, create a new list −var list = new List();Use the Add method and add the array elements to the list −for (int i = 0; i < arr.Length; i++) {    list.Add(arr[i]); }The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void Main() {       int[] arr = { 23, 66, 96, 110 };       var list = new List();       for (int i = 0; i < arr.Length; i++) {          list.Add(arr[i]);       }       foreach(int res in list) {          Console.WriteLine(res);       }    } }Output23 66 96 110

Disconnect from MySQL Database in PHP

Daniol Thomas
Updated on 22-Jun-2020 13:24:29

315 Views

PHP provides us mysql_close() function with the help of which we can disconnect from the MySQL database anytime. This function takes a single parameter, which is a connection returned by the mysql_connect() function. Its syntax is as follows −Syntaxbool mysql_close ( resource $link_identifier );Here, if a resource is not specified, then the last opened database is closed. This function returns true if it closes the connection successfully otherwise it returns false.

C# Program to Find If an Array Contains Duplicate

karthikeya Boyini
Updated on 22-Jun-2020 13:24:00

2K+ Views

Set an array −int[] arr = {    89,    12,    56,    89, };Now, create a new Dictionary −var d = new Dictionary < int, int > ();Using the dictionary method ContainsKey(), find the duplicate elements in the array −foreach(var res in arr) {    if (d.ContainsKey(res))    d[res]++;    else    d[res] = 1; }Here is the complete code −Example Live Demousing System; using System.Collections.Generic; namespace Demo {    public class Program {       public static void Main(string[] args) {          int[] arr = {             89, ... Read More

PHP Function to Establish MySQL Database Connection

mkotla
Updated on 22-Jun-2020 13:23:44

244 Views

PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success or FALSE on failure. Its syntax is as follows −Syntaxconnection mysql_connect(server, user, passwd, new_link, client_flag);Following table give us the parameters used in the syntax above −Sr.NoParameter & Description1ServerOptional − The host name running the database server. If not specified, then the default value will be localhost:33062UserOptional − The username accessing the database. If not specified, then the default will be the name of the user that owns the server process3PasswdOptional − The password of the user accessing the ... Read More

Establish MySQL Database Connection Using PHP Script

Krantik Chavan
Updated on 22-Jun-2020 13:22:49

191 Views

We can use following PHP script to make a MySQL database connection having user ‘guest’ and password ‘guest123’.           Connecting MySQL Server                  

PHP Function to Create a New Database

radhakrishna
Updated on 22-Jun-2020 13:22:24

176 Views

PHP uses mysql_query function to create a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure. Its syntax is as follows −Syntaxbool mysql_query( sql, connection );ExampleFollowings are the parameters used in this function −S. No.Parameter & DescriptionSqlRequired - SQL query to create a MySQL databaseconnectionOptional - if not specified, then the last opened connection by mysql_connect will be used.

Difference Between Dictionary and Hashtable in C#

Chandu yadav
Updated on 22-Jun-2020 13:22:20

648 Views

Hashtable is slower than Dictionary. For strongly-typed collections, the Dictionary collection is faster.HashtableHashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.Let us see an example −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Hashtable ht = new Hashtable();          ht.Add("E001", "Tom");          ht.Add("E098", "Amit");          ht.Add("E110", "Jack");         ... Read More

Advertisements