New Horizons Get Schooled Blog

Put the MySQL driver to bed and start using PDO to modernize PHP (PHP)

Posted on 12/27/18 10:00 AM by Get Schooled in PHP

MySQL is the Greenland shark of the internet, outliving other technologies and growing at a comparably slow pace. Technology has finally overcome MySQL, leaving it archaic. The superior replacement is PHP Data Objects (PDO). Not only does it implement PDO transition investment from several libraries to just one, but it also shortens the time to master the library, reduces maintenance requirements, and trims the number of bugs and points of failure. 

Apply this code to connect with databases using PDO: try { $conn = new PDO ( "mysql: host = localhost; dbname = database ' , $ user , $ pass ) ; $conn -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; } Catch ( PDOException $e ) {
Echo "ERROR:" . $e -> getMessage ( ) ; }

0 CommentsContinue Reading →

Shorten IF/ELSE constructions with ternary operators (PHP)

Posted on 10/30/18 8:00 AM by Get Schooled in PHP

Heavy code weighs the system down like a stick tied to a rock and thrown in a river. However, there is an opportunity to lighten code with ternary operators. IF/ELSE statements work great and are easy to code, but they usually end up too long and taxing. Fortunately, IF/ELSE statements aren’t always optimal or necessary, which is where the ternary operators step in.

Ternary operators use "(condition) ? (true return value) : (false return value)" statements to shorten IF/ELSE structures to a more manageable weight while retaining their original function. For example: $message = 'Greetings '.($user->get('first_name') ?: ‘Guest'); instead of $message = 'Greetings '.($user->is_logged_in() ? $user->get('first_name') : ‘Guest’);.

0 CommentsContinue Reading →

Use a Mediator instead of a Command Bus for superior code (PHP)

Posted on 9/13/18 10:16 AM by Get Schooled in PHP

A Command Bus is like a carrier pigeon dispatching a message, which it then delivers to the Command Handler. Like many functions in code development, there are multiple ways to execute the same command— with some being preferable over others, depending on the context. In most situations, a Command Bus results in emulated procedures, overcomplicated code, and loss of discoverability.

A Mediator is a superior alternative. Both a Command Bus and a Mediator can be overtaxed with too many responsibilities, but the Mediator shows its data in clear sight and can be easily monitored. For example use: $mediator->wakeUp(); instead of $commandbus->dispatch(new wakeUpCommand());.

0 CommentsContinue Reading →

Split large SQL files for data that can be successfully uploaded (SQL Server)

Posted on 8/30/18 11:49 AM by Get Schooled in SQL Server, in PHP

Just like parents tell their children to take smaller bites when they eat so they don’t choke, by default, phpMyAdmin can’t swallow file sizes larger than 2mb. This can cause quite the headache when you need to import a long SQL file that ends up too big.

Rather than breaking up the SQL file manually and possibly loosing vital information, run a simple command line script to take care of the heavy lifting for you. Not only will it improve accuracy, but it will also be completed in less time.

0 CommentsContinue Reading →

Redirect “Page Not Found” misdirect with error handling (PHP)

Posted on 8/24/18 9:45 AM by Get Schooled in PHP

When you change the main server and the hostname, it’s almost guaranteed that bookmarks will break and URLS will take users to a “Page Not Found” (404) error page. When handling a significant volume of redirects, it may be faster to simply setup a line of error handling that takes care of redirecting users for you during the transition.

To put this into action, add this entry to your httpd.conf: ErrorDocument 404 /redir-404.php3. Then, on your DocumentRoot redir-404.php3 write: <?php $redir = getenv(“REDIRECT_URL”); header(“Location:$redir”); ?>. This will send users to the old server so they don’t face a 404 error page while you implement a long-term solution.

0 CommentsContinue Reading →

Creating Simple Horizontal Bar Graph in PHP

Posted on 1/28/11 10:00 AM by Get Schooled in Auto Bar Graph Generator, in Bar Graph, in New Horizons Computer Learning Center, in Statistics, in Horizontal Bar Graph, in PHP, in Tips & Tricks

Creating Simple Horizontal Bar Graph in PHP

0 CommentsContinue Reading →

Displaying all images in PHP

Posted on 1/5/11 3:00 PM by Get Schooled in Image MIME, in internet explorer, in Mozilla Firefox, in Opera, in Photos, in PHP, in Tips & Tricks

Displaying all images in PHP

0 CommentsContinue Reading →

Search by Topic

    Lists by Topic

    see all

    Be at the center of it all.


    Knowledge Ninjas

    a web-based service that allows software application end users to access a subject matter expert in real-time via a chat interface to resolve questions or problems they encounter in their specific software.