Query that returns two character records from MySQL table

Today I will show you how to get records of 2 characters that are mixed in with multiple character records. This particular example I experienced from my work. All 52 states in US each has 2 names: full name and abbreviation name. For example: California is a full name and CA is its abbreviation. However in Canada a state has only full name. For example: Manitoba.

The issue here is that when you have a state table in your database that contains the states of USA and Canada. I will show what query you should use to filter the list of only US States.

Your state table will look like this picture:

The query you will have to use to get only the US states is:

  1. $sql_statement = “Select * from mydb.state_table where CHAR_LENGTH(state_abbr)  = 2”;

And here is the list of states returned by the query above.


Saturday April 3rd from 9:00pm to 11:00pm PST

247Apps Scheduled Maintenance


We will be upgrading our infrastructure improvements to provide greater reliability and performance for our customers.
From 9:00pm to 11:00pm PST, Saturday April 3rd, we will be conducting some hardware upgrades and security patches to our hosting platforms. Services for WordPress Website Builder Elementor, Rental Plugins, Housing Market Analysis, Charts, Custom Calculation, DownloadInsights customers will be affected. While you may continue to work in open applications, you may experience an interruption to web services during the maintenance period.
We apologize for any inconvenience this disruption may cause and thank you for your patience.

Thank you,
247AppsMobi – Web Services of MyNetworkSolution Dev Team

How to view all files in a directory using php.

With PHP version 5.0 and higher, you can apply a function called dir_scan() to return all the filenames in a directory.

$dir    = ‘dir_scan_test/’;
$files1 = scandir($dir);
The list of filenames will be in an array.

With PHP version 4.0 and lower, you have to use opendir($path) function to retrieve a list of files

So, compared to PHP4, applying PHP5 codes will be much cleaner and therefore your scripts will be executed faster.

MySQL Error Code 1215: “Cannot add foreign key constraint”

Why am I unable to create a constraint? The error message doesn’t help much. You just get the following line when you run this SQL statement:

ALTER TABLE user_class ADD FOREIGN KEY (user_id) REFERENCES user(id);

Error Code: 1215
Cannot add foreign key constraint

If you try running some of these SQL statements from mysql ( https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html#foreign-keys-adding ), still same error occurred without a reason. You may have to double check a few things within related tables and their fields.

1) The table or index the constraint refers to does not exist yet (usual when loading sql dumps).

2) The table or index in the constraint references misuses quotes.

3) The local key, foreign table or column in the constraint references have a typo.

4) The column the constraint refers to is not of the same type or width as the foreign column

5) The foreign object is not a KEY of any kind

6) The foreign key is a multi-column PK or UK, where the referenced column is not the leftmost one

7) Different charsets/collations among the two table/columns

8) Must be InnoDB

9) Using syntax shorthands to reference the foreign key

10) Using SET DEFAULT for a constraint action

Error using pyttsx3 is a text-to-speech conversion library in Python

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3.

import pyttsx3
engine = pyttsx3.init()

It shows errors:

Traceback (most recent call last):
  File "C:\Users\MyName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\MyName\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

If running into this type of error for this pip library, you can uninstall the current version and downgrade the library, using these commands:

pip uninstall pyttsx3
pip install pyttsx3==2.71

You’ll see this notification in the console:

Collecting pyttsx3==2.71
  Downloading pyttsx3-2.71-py3-none-any.whl (39 kB)
Requirement already satisfied: pypiwin32; "win32" in sys_platform in c:\users\MyName
\appdata\local\programs\python\python38-32\lib\site-packages (from pyttsx3==2.
71) (223)
Requirement already satisfied: pywin32>=223 in c:\users\MyName\appdata\local\progr
ams\python\python38-32\lib\site-packages (from pypiwin32; "win32" in sys_platfor
m->pyttsx3==2.71) (228)
Installing collected packages: pyttsx3
Successfully installed pyttsx3-2.71

Then try running this example again:

import pyttsx3
engine = pyttsx3.init()
engine.say("Hello, I'm fixed.")