How to search and replace in MySql

The code below will do the trick, this line can be modified to accomodate your needs. A where clause can also be added UPDATE databaseTableName SET tableColumnName = replace(tableColumnName,"findValue","replaceValue");

March 23, 2018 · 1 min · 29 words · icarnaghan

How to use the CONCAT MySql function to concatenate 2 table columns

The CONCAT function can be used to concatenate two strings to form a single string or two columns to form a single column. Say for Example you have a table users with columns name and surname and you would like to display both as one name you would use the CONCAT function to join the two fields as in the Example below SELECT CONCAT(name," ",surname) AS fullname FROM users; The above code will display something similar to Joe Soap should Joe be stored in the name column and Soap be stored in the surname column.

March 23, 2018 · 1 min · 95 words · icarnaghan

How to view the character set and collation on a database in MySql

Select your database via the command line: USE your_database; Then execute the following two commands: show variables like "character_set_database"; and show variables like "collation_database";

March 23, 2018 · 1 min · 24 words · icarnaghan

How-to create a MySQL database and assign user privileges to it

NOTE: Please note that this is done in the Command Line Interface. First login to the mySql server using root. mysql -uroot -pROOT_PASSWORD Replace ROOT_PASSWORD with the password for the root user. Once logged in we create a new database called TEST_DB replace with your database name create database TESTDB; Query OK, 1 row affected (0.00 sec) We grant access privileges to user MYUSER to connect to the mysql server from localhost using the password MYPASSWORD ...

March 23, 2018 · 1 min · 141 words · icarnaghan

Table 'performance_schema.session_variables' doesn't exist

Solution 1 Upgrade your MySql server. After the upgrade reboot the server mysql_upgrade -u root -p --force systemctl restart mysqld **Solution 2 **This solution is not permanent. After the next reboot of the MySql server all changes will be lost. mysql -u app -p mysql> set @@global.show_compatibility_56=ON; Solution 3 This solution is permanent. Locate and edit your MySql config file: my.cnf Under the [mysqld] config section add the following line: show_compatibility_56 = ON Sample: ...

March 23, 2018 · 1 min · 133 words · icarnaghan

What is the command for showing all tables within a database on a server

After your database has been selected using the use command eg. use database; you can type the show tables command to list all tables within the selected databaseeg. show tables;

March 23, 2018 · 1 min · 30 words · icarnaghan

What's the difference between RIGHT, LEFT, OUTER, INNER, JOIN

The difference is the way the tables are joined if no common records are available. RIGHT - RIGHT JOIN is the opposite of LEFT JOIN and the same as RIGHT OUTER JOIN. Shows all records from the right table and only matching records from the left table. LEFT - LEFT JOIN shows all records from the left table does not matter if matching records in the right table exists or not. Also the same as LEFT OUTER JOIN. ...

March 23, 2018 · 1 min · 147 words · icarnaghan

[function.file-put-contents]: failed to open stream: File name too long

Error: [function.file-put-contents]: failed to open stream: File name too long To solve this error you need to rename the filename so that the filename and extention together are no more than 255 characters, an easy way to do this is $filename=substr($name,0,251).'.pdf'; Note, that we used the character count 251 since 251 + the 4 characters for the extention together add up to 255 characters.

March 22, 2018 · 1 min · 64 words · icarnaghan

Calculating the date difference in days using PHP

If you have 2 dates and you need to calculate the total days between these two dates using PHP you will need to do the following First, we need to convert the two dates into UNIX timestamps in seconds $date1 = strtotime('2010-10-12'); $date2 = strtotime('2011-11-12'); Calculate the difference between these two dates in seconds $diff = $date2-$date1; Get the total of Days $days = floor($diff/(60*60*24)); The floor function is there to get complete days. 60*60*24 means that each day has 24 hours, each hour has 60 minutes and each minute has 60 seconds. ...

March 22, 2018 · 1 min · 107 words · icarnaghan

Calculating the difference in days between 2 dates in PHP

$startDate = '1999-03-12'; $endDate = '2011-03-12'; $days = (strtotime($endDate)-strtotime($startDate)) / (60 * 60 * 24); echo $days; //Will output 4383 In the above example we have a startdate and a enddate. We need to find out how many days are between the startdate and the enddate. We convert both dates to a UNIX Timestamp using the strtotime PHP function. After the conversion we substract the startdate from the endate and then divide it by the number of seconds in a day (60*60*24). ...

March 22, 2018 · 1 min · 97 words · icarnaghan