This nifty article will teach you how to use the SQL panel in cPanel. Every now and then you will have need to run SQL commands directly onto the DB rather than using your server side scripting language and the web. cPanel makes it very easy to do this. If you are used to writing SQL Procedures in PHP, for example, you will come to notice very quickly that it is very similar. Raw SQL syntax is a little different but you will catch on very quick. First, open up your cPanel. Sometimes, depending upon what type of account you have there could be TWO way’s to login to your cPanel with Arvixe. Make sure that you choose the HTTPS (SEURE METHOD). Once in cPanel go to your PHP MY ADMIN.
Now once in your phpMyAdmin you need to open up one of your Databases. Clearly, you should have already set up a DB. If not, go to MySQL DATABASES and set one up. There are plenty of other tutorials for this :). Now, once in php and having selected a database, click on the SQL TAB
Let’s set up a little example of an UPDATE QUERY. Say you wish to UPDATE a field in the ADDRESS TABLE.
Disclaimer: DO NOT ATTEMPT TO RUN THESE TESTS ON A LIVE WEBSITE. IF YOU ARE THEN MAKE A BACK UP FIRST.
When opening the SQL TAB you will see a text input area. Here is where you will insert your syntax. Place the following syntax:
UPDATE `dbprefix_customer` SET firstname = 'joseph' WHERE customer_id ='some number';
In the above code you are updating the customer with the customer ID of _____. If you do not specify a WHERE CLAUSE then it will update every single first name to ‘joseph’. This would normally not be a desirable result so it is always recommended using WHERE or WHERE/AND when doing updates.
SELECT * FROM `dbprefix_customer` WHERE firstname <> 'joseph' ORDER BY customer_id DESC;
So here we are selecting all rows in the customer table where the customer’s names are not joseph and showing results by customer ID and DESCENDING.
The SQL console is very powerful in fact you can design your entire DB in it if you know syntax well enough. My next tutorial will be on something similar but using the Opencart framework to run SQL QUERIES instead with PHP.