MySQL DROP statement using phpMyAdmin

The MySQL DROP statement is one of many powerful DDL commands. Be it ALTER TABLE some_table DROP some_column or DROP some_table, this type of command can drastically change your data landscape because in executing MySQL DROP, you are completely removing objects from the database! If you are using the phpMyAdmin web interface, you can execute the MySQL DROP statement with just a few mouse clicks. Continue reading to see how…

[Keep reading for more SQL database and Python/PHP-centric content >>>]

PHP PDO lastInsertId() method with examples in MySQL

MySQL has an AUTO_INCREMENT column attribute which automatically generates a consistent integer value upon a successful (or not) INSERT. Oftentimes, this attribute is set on a column deemed the PRIMARY KEY. Therefore, providing a unique value for the column and ensuring each rows’ individual identity. The LAST_INSERT_ID() function returns the most recently generated value for a column with the AUTO_INCREMENT attribute. Many times, you use this value further in query processing (E.g., link a newly signed-on customers’ information to a joining table of orders, ensure referential integrity between parent and child tables using a FOREIGN KEY and PRIMARY KEY, INSERT into another related one-to-one table, etc…). The PDO PHP library has a like-named class method, lastInsertId(), which provides the same functionality as LAST_INSERT_ID() in a PHP context. In this post, I’ll visit lastInsertId() with a simple example. Continue reading to learn more…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]

Use phpMyAdmin to change column name and datatype in MySQL

Using the MySQL ALTER TABLE command, you can easily change an existing columns’ name and datatype. With just a few clicks, you can do the same in the phpMyAdmin visual web interface. For many developers, this interface is the one they lean on most while programming so it can’t hurt to know how to do it yourself should you find yourself programming in this environment…

Keep reading for more SQL database and Python/PHP-centric content

Beginning Perspective on PHP Arrays

Arrays are one of the most important PHP data types. An array is composed of 1 or more key/value pairs and can store any type (E.g., strings, integers, decimal numbers, etc…). Array values (or elements) are accessed via a key (index), which is either numerical-based or a string-based. Arrays composed of string-based indexes are known as associative arrays. Keep reading for an introductory-level coverage of PHP arrays, as I understand them…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]

Sorting associative arrays in PHP with array_multisort() – New learning

If you write MySQL queries, at some point you are going to have to provide query results in a specific order. To impose any ordering in MySQL (this applies to SQL overall and is not directed only at MySQL), you have to use the ORDER BY clause. Without it, there is no guaranteed order. The database is free to send back query results in any order. As I learn PHP, I make it a point to explore both the MySQL side, along with the PHP side in regards to similar type tasks and the efficiency of each. So far in my PHP journey, I have found that arrays are used quite extensively. In this post, I’ll cover array_multisort() – one of many in-built PHP functions – used for sorting arrays. In the context of the example data for this post, the arrays are populated by an unordered MySQL query. Let’s see one example of how you can establish a sorting order in a PHP array, that is populated from an unordered MySQL query…

[Keep reading for more SQL database and Python/PHP-centric content >>>]