Home Blog Page 2

Default Media Query Sizes for Twitter Bootstrap

As someone who uses Twitter Bootstrap for front-end responsive development, I constantly have to look up bootstrap media query breakpoints. Some instances as an example are, when I need to use JavaScript for dynamic content manipulation such as events fired on window widths, or even adding some extra CSS classes to format content.

This keeps taking me to the bootstrap scaffolding guide to look for these values. So I thought I will document them in one place for easy reference.

You can find the different Bootstrap Breakpoints by version below.

Bootstrap 4 Media Query Breakpoints

Default mobile first breakpoints

// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap

// Anything below 576px - xs

// Small devices (landscape phones, 576px and up) - sm
@media (min-width: 576px) { ... }

// Medium devices (tablets, 768px and up) - md
@media (min-width: 768px) { ... }

// Large devices (desktops, 992px and up) - lg
@media (min-width: 992px) { ... }

// Extra large devices (large desktops, 1200px and up) - xl
@media (min-width: 1200px) { ... }

Mobile first SASS mixins

@include media-breakpoint-up(xs) { ... }
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }

Large display breakpoints

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }

// Small devices (landscape phones, less than 768px)
@media (max-width: 767px) { ... }

// Medium devices (tablets, less than 992px)
@media (max-width: 991px) { ... }

// Large devices (desktops, less than 1200px)
@media (max-width: 1199px) { ... }

// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width

Large display SASS mixins

@include media-breakpoint-down(xs) { ... }
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }

 

Bootstrap 3 Media Query Breakpoints

Default Mobile First Breakpoints

/* Large desktop */
@media (min-width: 1200px) { ... }
 
/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }
 
/* Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }
 
/* Landscape phones and down */
@media (max-width: 480px) { ... }

LESS variables

/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }

 

Bootstrap 2.3.2 Media Query Breakpoints

Label Layout width Column width Gutter width
Large display 1200px and up 70px 30px
Default 980px and up 60px 20px
Portrait tablets 768px and above 42px 20px
Phones to tablets 767px and below Fluid columns, no fixed widths
Phones 480px and below Fluid columns, no fixed widths

Default Mobile First Breakpoints

/* Large desktop */
@media (min-width: 1200px) { ... }
 
/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }
 
/* Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }
 
/* Landscape phones and down */
@media (max-width: 480px) { ... }

WordPress AMP Automattic Plugin Enable for Custom Post Types(CPT)

0

wordpress_automatic_amp_earlIf you are on the band wagon to enable AMP on your WordPress website and are using the AMP Plugin by Automattic, you may realize that it does not work for custom post types right out of the gate. For this you need to make a small tweak by adding some modification to your theme or plugin code.

In the example below lets assume that your CPT is registered as ‘resources’ which we use as the first parameter of the function add_post_type_support() and you can change it to what ever your actual CPT is, duplicate that line with the new CPT names if you have multiple CPT’s. ‘cpt_enable_amp’ is passed to add_action() is just a function name and you can name it what ever you want as long as the function name below it is the same name and there is no other function named the same.


//If on a custom theme code would go in functions.php of the theme
add_action( 'init', 'te_cpt_enable_amp', 20 );

function te_cpt_enable_amp() {
    if ( ! defined( 'AMP_QUERY_VAR' ) ) {
        return; // do not add support if AMP plugin is not detected
    }
    add_post_type_support( 'resources', AMP_QUERY_VAR );
    add_post_type_support( 'news', AMP_QUERY_VAR ); // if you have another CPT called news
}

Once you are done with this, simply go to your front page URL for the post and add /amp or /?amp=1 the end of your URL. If you already have other parameters you may need to add &amp=1 and append it to the rest of the query string.

eg:


http://www.yoursite.com/resources/whitepaper-enable-amp-on-wordpress-custom-post-type/amp
http://www.yoursite.com/resources/whitepaper-enable-amp-on-wordpress-custom-post-type/?amp=1

Tor TORRC Country Codes Listing

0

Country                               Code
ASCENSION ISLAND                      {ac}
AFGHANISTAN                           {af}
ALAND                                 {ax}
ALBANIA                               {al}
ALGERIA                               {dz}
ANDORRA                               {ad}
ANGOLA                                {ao}
ANGUILLA                              {ai}
ANTARCTICA                            {aq}
ANTIGUA AND BARBUDA                   {ag}
ARGENTINA REPUBLIC                    {ar}
ARMENIA                               {am}
ARUBA                                 {aw}
AUSTRALIA                             {au}
AUSTRIA                               {at}
AZERBAIJAN                            {az}
BAHAMAS                               {bs}
BAHRAIN                               {bh}
BANGLADESH                            {bd}
BARBADOS                              {bb}
BELARUS                               {by}
BELGIUM                               {be}
BELIZE                                {bz}
BENIN                                 {bj}
BERMUDA                               {bm}
BHUTAN                                {bt}
BOLIVIA                               {bo}
BOSNIA AND HERZEGOVINA                {ba}
BOTSWANA                              {bw}
BOUVET ISLAND                         {bv}
BRAZIL                                {br}
BRITISH INDIAN OCEAN TERR             {io}
BRITISH VIRGIN ISLANDS                {vg}
BRUNEI DARUSSALAM                     {bn}
BULGARIA                              {bg}
BURKINA FASO                          {bf}
BURUNDI                               {bi}
CAMBODIA                              {kh}
CAMEROON                              {cm}
CANADA                                {ca}
CAPE VERDE                            {cv}
CAYMAN ISLANDS                        {ky}
CENTRAL AFRICAN REPUBLIC              {cf}
CHAD                                  {td}
CHILE                                 {cl}
PEOPLE'S REPUBLIC OF CHINA            {cn}
CHRISTMAS ISLANDS                     {cx}
COCOS ISLANDS                         {cc}
COLOMBIA                              {co}
COMORAS                               {km}
CONGO                                 {cg}
CONGO (DEMOCRATIC REPUBLIC)           {cd}
COOK ISLANDS                          {ck}
COSTA RICA                            {cr}
COTE D IVOIRE                         {ci}
CROATIA                               {hr}
CUBA                                  {cu}
CYPRUS                                {cy}
CZECH REPUBLIC                        {cz}
DENMARK                               {dk}
DJIBOUTI                              {dj}
DOMINICA                              {dm}
DOMINICAN REPUBLIC                    {do}
EAST TIMOR                            {tp}
ECUADOR                               {ec}
EGYPT                                 {eg}
EL SALVADOR                           {sv}
EQUATORIAL GUINEA                     {gq}
ESTONIA                               {ee}
ETHIOPIA                              {et}
FALKLAND ISLANDS                      {fk}
FAROE ISLANDS                         {fo}
FIJI                                  {fj}
FINLAND                               {fi}
FRANCE                                {fr}
FRANCE METROPOLITAN                   {fx}
FRENCH GUIANA                         {gf}
FRENCH POLYNESIA                      {pf}
FRENCH SOUTHERN TERRITORIES           {tf}
GABON                                 {ga}
GAMBIA                                {gm}
GEORGIA                               {ge}
GERMANY                               {de}
GHANA                                 {gh}
GIBRALTER                             {gi}
GREECE                                {gr}
GREENLAND                             {gl}
GRENADA                               {gd}
GUADELOUPE                            {gp}
GUAM                                  {gu}
GUATEMALA                             {gt}
GUINEA                                {gn}
GUINEA-BISSAU                         {gw}
GUYANA                                {gy}
HAITI                                 {ht}
HEARD & MCDONALD ISLAND               {hm}
HONDURAS                              {hn}
HONG KONG                             {hk}
HUNGARY                               {hu}
ICELAND                               {is}
INDIA                                 {in}
INDONESIA                             {id}
IRAN, ISLAMIC REPUBLIC OF             {ir}
IRAQ                                  {iq}
IRELAND                               {ie}
ISLE OF MAN                           {im}
ISRAEL                                {il}
ITALY                                 {it}
JAMAICA                               {jm}
JAPAN                                 {jp}
JORDAN                                {jo}
KAZAKHSTAN                            {kz}
KENYA                                 {ke}
KIRIBATI                              {ki}
KOREA, DEM. PEOPLES REP OF            {kp}
KOREA, REPUBLIC OF                    {kr}
KUWAIT                                {kw}
KYRGYZSTAN                            {kg}
LAO PEOPLE'S DEM. REPUBLIC            {la}
LATVIA                                {lv}
LEBANON                               {lb}
LESOTHO                               {ls}
LIBERIA                               {lr}
LIBYAN ARAB JAMAHIRIYA                {ly}
LIECHTENSTEIN                         {li}
LITHUANIA                             {lt}
LUXEMBOURG                            {lu}
MACAO                                 {mo}
MACEDONIA                             {mk}
MADAGASCAR                            {mg}
MALAWI                                {mw}
MALAYSIA                              {my}
MALDIVES                              {mv}
MALI                                  {ml}
MALTA                                 {mt}
MARSHALL ISLANDS                      {mh}
MARTINIQUE                            {mq}
MAURITANIA                            {mr}
MAURITIUS                             {mu}
MAYOTTE                               {yt}
MEXICO                                {mx}
MICRONESIA                            {fm}
MOLDAVA REPUBLIC OF                   {md}
MONACO                                {mc}
MONGOLIA                              {mn}
MONTENEGRO                            {me}
MONTSERRAT                            {ms}
MOROCCO                               {ma}
MOZAMBIQUE                            {mz}
MYANMAR                               {mm}
NAMIBIA                               {na}
NAURU                                 {nr}
NEPAL                                 {np}
NETHERLANDS ANTILLES                  {an}
NETHERLANDS, THE                      {nl}
NEW CALEDONIA                         {nc}
NEW ZEALAND                           {nz}
NICARAGUA                             {ni}
NIGER                                 {ne}
NIGERIA                               {ng}
NIUE                                  {nu}
NORFOLK ISLAND                        {nf}
NORTHERN MARIANA ISLANDS              {mp}
NORWAY                                {no}
OMAN                                  {om}
PAKISTAN                              {pk}
PALAU                                 {pw}
PALESTINE                             {ps}
PANAMA                                {pa}
PAPUA NEW GUINEA                      {pg}
PARAGUAY                              {py}
PERU                                  {pe}
PHILIPPINES (REPUBLIC OF THE)         {ph}
PITCAIRN                              {pn}
POLAND                                {pl}
PORTUGAL                              {pt}
PUERTO RICO                           {pr}
QATAR                                 {qa}
REUNION                               {re}
ROMANIA                               {ro}
RUSSIAN FEDERATION                    {ru}
RWANDA                                {rw}
SAMOA                                 {ws}
SAN MARINO                            {sm}
SAO TOME/PRINCIPE                     {st}
SAUDI ARABIA                          {sa}
SCOTLAND                              {uk}
SENEGAL                               {sn}
SERBIA                                {rs}
SEYCHELLES                            {sc}
SIERRA LEONE                          {sl}
SINGAPORE                             {sg}
SLOVAKIA                              {sk}
SLOVENIA                              {si}
SOLOMON ISLANDS                       {sb}
SOMALIA                               {so}
SOMOA,GILBERT,ELLICE ISLANDS          {as}
SOUTH AFRICA                          {za}
SOUTH GEORGIA, SOUTH SANDWICH ISLANDS {gs}
SOVIET UNION                          {su}
SPAIN                                 {es}
SRI LANKA                             {lk}
ST. HELENA                            {sh}
ST. KITTS AND NEVIS                   {kn}
ST. LUCIA                             {lc}
ST. PIERRE AND MIQUELON               {pm}
ST. VINCENT & THE GRENADINES          {vc}
SUDAN                                 {sd}
SURINAME                              {sr}
SVALBARD AND JAN MAYEN                {sj}
SWAZILAND                             {sz}
SWEDEN                                {se}
SWITZERLAND                           {ch}
SYRIAN ARAB REPUBLIC                  {sy}
TAIWAN                                {tw}
TAJIKISTAN                            {tj}
TANZANIA, UNITED REPUBLIC OF          {tz}
THAILAND                              {th}
TOGO                                  {tg}
TOKELAU                               {tk}
TONGA                                 {to}
TRINIDAD AND TOBAGO                   {tt}
TUNISIA                               {tn}
TURKEY                                {tr}
TURKMENISTAN                          {tm}
TURKS AND CALCOS ISLANDS              {tc}
TUVALU                                {tv}
UGANDA                                {ug}
UKRAINE                               {ua}
UNITED ARAB EMIRATES                  {ae}
UNITED KINGDOM (no new registrations) {gb}
UNITED KINGDOM                        {uk}
UNITED STATES                         {us}
UNITED STATES MINOR OUTL.IS.          {um}
URUGUAY                               {uy}
UZBEKISTAN                            {uz}
VANUATU                               {vu}
VATICAN CITY STATE                    {va}
VENEZUELA                             {ve}
VIET NAM                              {vn}
VIRGIN ISLANDS (USA)                  {vi}
WALLIS AND FUTUNA ISLANDS             {wf}
WESTERN SAHARA                        {eh}
YEMEN                                 {ye}
ZAMBIA                                {zm}
ZIMBABWE                              {zw}

Domain Directing and Virtual Host Setup for WAMP Server

0

wamp_guy_leftearlAs with most developers who install WAMP you are probably working with localhost as your development domain name and directories for your projects.

For demonstration purposes lets say you are developing a WordPress or Joomla based site for Google where the domain is http://www.google.com

So you would typically create this directory structure where all your project files would reside, assuming Wamp is installed in the C Drive.

c:\wamp\www\google

 

Now you would be accessing this domain with the URL

http://localhost/google

 

And during your development life cycle all your links in the database and configuration will point to

http://localhost/google

 

This is not ideal when it comes time to migrate the site to the actual domain as now you will have to do some configuration and database maintenance to correct the links to point to the correct domain name.

So lets do it the right way.

Look in your Wamp installation directory and find the file named

httpd.conf

 

Scroll right to the bottom and you will see a couple of lines that look like

#IncludeOptional "c:/wamp/vhosts/*"
Include "c:/wamp/alias/*"

Uncomment the top line so it looks like making adjustments to reflect your Wamp installation path.

IncludeOptional "c:/wamp/vhosts/*"
Include "c:/wamp/alias/*"

Now find your Windows hosts. file which is generally located in

C:\Windows\System32\drivers\etc

You can try to directly open the file below in the text editor to save time trying to find it.

C:\Windows\System32\drivers\etc\hosts.

Once it is open the content will look something like this

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

Create a new line at the bottom with the line below without the hash(#) at the beging and save the file.

127.0.0.1 google.com

Now when ever you try to go to google.com your browser will look for the domain on your computer or localhost automatically, so if you need to access the actual domain just add the hash(#) in front and save or delete the line and save.

Next go to the follow directory

C:\wamp\vhosts

and open the file httpd-vhosts.conf for editing

For the sake of simplicity add this Apache directive towards the bottom of the file and save it, you can add extended parameters to the VirtualHost directive if you wish.

<VirtualHost *:80>
ServerName google.com
DocumentRoot "c:/wamp/www/google/"
</VirtualHost>

That’s it now restart Apache and enjoy development on your project with less hassle at the end.

 

WPScan Usage & MAN Page

wpscan_earl-150

WPScan Usage & MAN Page

Do ‘non-intrusive’ checks …

ruby ./wpscan.rb --url www.example.com

Do wordlist password brute force on enumerated users using 50 threads …

ruby ./wpscan.rb --url www.example.com --wordlist darkc0de.lst --threads 50

Do wordlist password brute force on the ‘admin’ username only …

ruby ./wpscan.rb --url www.example.com --wordlist darkc0de.lst --username admin

Enumerate installed plugins …

ruby ./wpscan.rb --url www.example.com --enumerate p

Enumerate installed themes …

ruby ./wpscan.rb --url www.example.com --enumerate t

Enumerate users …

ruby ./wpscan.rb --url www.example.com --enumerate u

Enumerate installed timthumbs …

ruby ./wpscan.rb --url www.example.com --enumerate tt

Use a HTTP proxy …

ruby ./wpscan.rb --url www.example.com --proxy 127.0.0.1:8118

Use a SOCKS5 proxy … (cURL >= v7.21.7 needed)

ruby ./wpscan.rb --url www.example.com --proxy socks5://127.0.0.1:9000

Privoxy TOR with default ip and port

ruby ./wpscan.rb --url www.example.com --proxy 127.0.0.1:8118

Use custom content directory …

ruby ./wpscan.rb -u www.example.com --wp-content-dir custom-content

Use custom plugins directory …

ruby ./wpscan.rb -u www.example.com --wp-plugins-dir wp-content/custom-plugins

Update the DB …

ruby ./wpscan.rb --update

Debug output …

ruby ./wpscan.rb --url www.example.com --debug-output 2>debug.log

MAN Page

Some values are settable in a config file, see the example.conf.json

--update                            Update to the database to the latest version.
--url       | -u <target url>       The WordPress URL/domain to scan.
--force     | -f                    Forces WPScan to not check if the remote site is running WordPress.
--enumerate | -e [option(s)]        Enumeration.
  option :
    u        usernames from id 1 to 10
    u[10-20] usernames from id 10 to 20 (you must write [] chars)
    p        plugins
    vp       only vulnerable plugins
    ap       all plugins (can take a long time)
    tt       timthumbs
    t        themes
    vt       only vulnerable themes
    at       all themes (can take a long time)
  Multiple values are allowed : "-e tt,p" will enumerate timthumbs and plugins
  If no option is supplied, the default is "vt,tt,u,vp"

--exclude-content-based "<regexp or string>"
                                    Used with the enumeration option, will exclude all occurrences based on the regexp or string supplied.
                                    You do not need to provide the regexp delimiters, but you must write the quotes (simple or double).
--config-file  | -c <config file>   Use the specified config file, see the example.conf.json.
--user-agent   | -a <User-Agent>    Use the specified User-Agent.
--cookie <String>                   String to read cookies from.
--random-agent | -r                 Use a random User-Agent.
--follow-redirection                If the target url has a redirection, it will be followed without asking if you wanted to do so or not
--batch                             Never ask for user input, use the default behaviour.
--no-color                          Do not use colors in the output.
--wp-content-dir <wp content dir>   WPScan try to find the content directory (ie wp-content) by scanning the index page, however you can specified it.
                                    Subdirectories are allowed.
--wp-plugins-dir <wp plugins dir>   Same thing than --wp-content-dir but for the plugins directory.
                                    If not supplied, WPScan will use wp-content-dir/plugins. Subdirectories are allowed
--proxy <[protocol://]host:port>    Supply a proxy. HTTP, SOCKS4 SOCKS4A and SOCKS5 are supported.
                                    If no protocol is given (format host:port), HTTP will be used.
--proxy-auth <username:password>    Supply the proxy login credentials.
--basic-auth <username:password>    Set the HTTP Basic authentication.
--wordlist | -w <wordlist>          Supply a wordlist for the password brute forcer.
--username | -U <username>          Only brute force the supplied username.
--usernames     <path-to-file>      Only brute force the usernames from the file.
--threads  | -t <number of threads> The number of threads to use when multi-threading requests.
--cache-ttl       <cache-ttl>       Typhoeus cache TTL.
--request-timeout <request-timeout> Request Timeout.
--connect-timeout <connect-timeout> Connect Timeout.
--max-threads     <max-threads>     Maximum Threads.
--help     | -h                     This help screen.
--verbose  | -v                     Verbose output.
--version                           Output the current version and exit.<span face="PT Sans, sans-serif" data-mce-style="font-family: 'PT Sans', sans-serif;" style="font-family: 'PT Sans', sans-serif;"><span style="font-size: 15px; line-height: 23px; white-space: normal;">
</span></span>

wp_insert_post Consuming Large Amounts of Memory

0

wordpress_earl-150If you are using “wp_insert_post” to insert large amounts of posts from external scripts or even code within WordPress and notice “wp_insert_post memory consumption” is very high, “increasing PHP memory” may not be the solution you are looking for.

The reason for this is simply the fact that Wordpres Caches its queries and you need to prevent this from happening for the duration of execution of your code.

To accomplish this make the following two changes.

Add this line to your wp-config.php file

define( 'SAVEQUERIES', false );

This prevents WordPress from caching all the SQL Query’s and run-time results for the session.

Next add the following line in your script file, the location can be before the “wp_insert_post loop” or after you have defined WordPress.

wp_suspend_cache_addition(true);

This will prevent the result of each wp_insert_post from getting into the “Worpdress Object Cache” which is generally what consumes the memory.

Now you can insert millions of posts into WordPress without ever having to worry about memory issues.

For an internal scripts make sure you turn back wp_suspend_cache_addition(true); on once your inserts have been completed.

SOLVED Fatal error: Call to undefined function get_option()

0

wordpress_error_earl-150If you suddenly start to get the error “Fatal error: Call to undefined function get_option() in” “/wp-admin/admin.php” or “Fatal error: Call to undefined function wp() in” “/wp-blog-header.php on line %%” when trying to access the admin of your WordPress website chances are your WordPress installation has got corrupt.

Geneally it could be a few files that need replacing but its a good idea to replace the entire WordPress Core installation.

At this point you will need to identify the WordPress version installed and then download the same version from https://wordpress.org/download/release-archive/ then just overwrite the existing installation files with the contents of the file you download.

To find the version of WordPress installed you can generally go to the front page of your site(which should be working) and view the source. Then search and find the line that looks like
<meta name="generator" content="WordPress 4.0.4" />

In this example the version is 4.0.4

Export or Backup All MySQL Databases From The Command Line

0

Exporting or Backing up all MySQL Databases is a very common task you will need to accomplish at some point in your development experience.

MySQL provides a very handy Command Line tool called mysqldump (pronounced MySQL Dump) which does exactly that.

Some general reasons would be:
Performing periodic MySQL Database Backups.
Moving MySQL databases from one server to another.
Innodb or other DB engine maintenance.

Backing up all MySQL Databases into one .SQL

Running this command is both the same for Linux as well as Windows and we assume that you are on the same server(locahost), if you are connecting to another server you can specify the server hostname or IP by also specifying the “-h hostname” parameter.

mysqldump -u username -p --databases > databases.sql

While it is not generally recommended, some people also like specifying the password in the command line.

mysqldump -u username -p password --databases > databases.sql
Linux Specific Commands

If you would also like to gzip compress the file in one go then you can run the following command on linux.

mysqldump -u username -p password --databases | gzip > databases.sql.gz

Linux: ZIP Multiple Directories Into Individual Files

0

earllinux-150If you have been trying to ZIP multiple directories into individual files, this simple command will do just that for you.

ZIP Without Sub directories

for dirname in */; do zip "${dirname%/}.zip" "$dirname"; done

ZIP With Sub directories

Specifying the -r parameter to the zip program it will also include any sub directories of the individual directories that you are creating the individual zip files for.


for dirname in */; do zip -r "${dirname%/}.zip" "$dirname"; done

WHMCS SQL Helper Functions

0

Wondering how to access your WHMCS database while developing templates, custom pages or addon modules? well dont look any further. WHMCS  offers a full array of SQL Helper Functions to SELECT, INSERT and UPDATE information right form within WHMCS itself.

Do I have to create a database connection?

WHMCS maintains a connection to the database throughout each user interaction which enables you to leverage and utilize this same connection using the  provided SQL Helper Functions.

Lets dive in and take a look at what is available

WHMCS provides a set of SQL Helper Functions for database interactions within the WHMCS environment, ideal for developers creating templates, custom pages, or addon modules. These functions allow for effective SELECT, INSERT, and UPDATE operations directly within WHMCS.

Full Queries

full_query($query)

Execute any SQL query, particularly useful for complex queries beyond basic operations.

Parameters

  • $query (string): The raw SQL query to be executed.

Usage

full_query("SELECT * FROM tblclients WHERE status = 'Active'");

Notes

  • No data sanitation or sanity checking. Sanitize inputs beforehand to prevent SQL injections.
  • Suitable for complex SQL operations not supported by other helper functions.

Select Queries

select_query($table, $fields, $where, $sort, $sortorder, $limits, $join)

Retrieve data from the database with parameters to refine the query.

Parameters

  • $table (string): Name of the table.
  • $fields (string/array): Fields to select, comma-separated or array.
  • $where (array): Conditions for the query.
  • $sort (string, optional): Field to sort by.
  • $sortorder (string, optional): ‘ASC’ or ‘DESC’.
  • $limits (string, optional): Record selection range, e.g., “0,10”.
  • $join (string, optional): For inner join with another table.

Usage

select_query('tblclients', 'id,firstname,lastname', array('status' => 'Active'), 'id', 'ASC', '0,10');

Notes

  • $where is an associative array with keys as column names.
  • $sort, $sortorder, and $limits are optional for refining the query.

Insert Queries

insert_query($table, $data)`

Simplify the process of inserting data into the database.

Parameters

  • $table (string): Table name for data insertion.
  • $data (array): Associative array with column names as keys and data to insert as values.

Usage

insert_query('tblclients', array('firstname' => 'John', 'lastname' => 'Doe'));

Notes

  • Keys in $data should correspond to column names.
  • Data is automatically escaped for SQL injection protection.

Exceptions

  • Exception if the table does not exist.
  • Exception for key-column mismatch.