PHP – Simple PDO Class for Connecting to a MySQL Database

Here’s an extremely basic, reusable PHP and MySQL based PDO class for easily connecting to multiple database servers simultaneously within a script without having to go through a bunch of hoopla. Tidbits have been pieced together from the following sources with a little tweaking of my own (such as the ability to have default database values or to pass them as arguments):
http://simple_pdo_implementation.onlinephpfunctions.com/
http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/
http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access–net-12059
Continue reading “PHP – Simple PDO Class for Connecting to a MySQL Database”

MySQL Script – Alter/Convert All Tables in a Database from MyISAM to InnoDB

Pieced together from various tutorials on the web with a lot of my own additions, here is a snippet of SQL that will alter or convert all tables in a database from “MyISAM” to “InnoDB”. As long as your MySQL user account has privileges to create stored procedures, all you have to do is simply edit the @DATABASE_NAME variable at the top of the script and run it in PhpMyAdmin if you’ve got it. Enjoy! Continue reading “MySQL Script – Alter/Convert All Tables in a Database from MyISAM to InnoDB”

Bash Script – Log Concurrent Asterisk Calls to MySQL and Other Useful One-Liners

Here is a quick and dirty bash script I threw together today to log the concurrent calls for each of my long distance trunks in Asterisk to a MySQL database to be able to quickly analyze usage trends. Sure there is probably other open-source software out there that can do this and give pretty little graphs and what not (cdr-stats or maybe queue metrics come to mind), but where’s the fun in that? As I mentioned, the script is extremely primitive (just the bare minimum as I didn’t have much time to spend on it) and contains no error checking whatsoever but it could also be used as a pretty handy one-liner in bash.

Show all active SIP Calls on a single trunk

asterisk -x "core show channels verbose" | grep "^SIP/yourSIPTrunkName-"

Show concurrent number of SIP Calls on a single trunk

asterisk -x "core show channels verbose" | grep -c "^SIP/yourSIPTrunkName-"

Show all active DAHDI calls on channels 1-24
Continue reading “Bash Script – Log Concurrent Asterisk Calls to MySQL and Other Useful One-Liners”

Mikrotik Scripting – Array Push Function

Since the scripting language at the moment on Router OS version 6.13 is lacking in the array editing department, here is a simple array push function I created.

# Usage: [$arrayPush <$array name> <value> <key position to place value (0-n or -1)>]
# Input an array name, value, and the key position to push the value to. To push value to the end of the array, enter -1.
# If array doesn't already exist, you must declare the variable and set it to "" before calling the function.
 Continue reading "Mikrotik Scripting – Array Push Function"

Mikrotik Scripting – Function to Split an IP Address into an Array

If you are unfamiliar with Mikrotik networking equipment, do yourself a favor and check them out at mikrotik.com or routerboard.com. Mikrotik uses Router OS, a Linux based operating system. In my eyes, they are every bit as comparable to Cisco at a fraction of the price with an impressive and robust GUI. I’ve been using them in production environments for six years with outstanding results. What other networking equipment has it’s own scripting language? None that I know of. The CCR series of routers with up to 36 processor cores are unparalleled in performance and flexibility.
Continue reading “Mikrotik Scripting – Function to Split an IP Address into an Array”