This article explains how you can manage the MySQL database(s) for your Linux cPanel account, and how to code a connection to them in PHP.
First log on to the cPanel Control Panel by opening a Web browser and browsing to http://myaccount.myzen.co.uk/cpanel/ or http://mydomain/cpanel/. Once logged in scroll to the Databases section.
Click MySQL Databases.
Enter the following information:
Click Create Database. NOTE: You may only create as many databases as defined by the cPanel service you have purchased from Zen.
Once the database is created click Go Back to return to the MySQL management page.
Scroll to the section labeled MySQL Users. If you do not have any existing database users you can create one here. If you existing users you may use these instead.
To create a new user enter the following information:
Once done click Create User.
You will now need to assign the user to a database. To do this select the user and database they should access from the drop-down boxes and click Add. Your database should now be ready to use.
In order to add tables and data to your database(s) you can run SQL statements from scripts on your Web page, or alternatively use phpMyAdmin. This can be found on the front page of your cPanel Control Panel under the heading Databases.
To log in to phpMyAdmin click phpMyAdmin.
This will log you on to the phpMyAdmin utility which allows you to manage your databases. Documentation for phpMyAdmin can be found by selecting the link phpMyAdmin documentation on this page.
To connect to your MySQL database you will first need to code a PHP page which includes a connection to your database. Sample code is printed below:
<?
$dbConn = @mysql_pconnect ("localhost", "myUserID", "myPassword");
if (!$dbConn) { echo "<p>Error: Could not connect to Database.</p>"; exit; }
echo "<p>Connect to database successful.</p>";
?>
// Tell mySQL what DB to connect to mysql_select_db("myDatabase");
// Create a query string $stSQL = "select * from tTemp;";
// Execute the query $rs = mysql_query($stSQL);
// get the number of rows returned, then disply it $rowCount = mysql_num_rows($rs);
echo "<p>Number of rows in table is " .$rowCount." </p>"; echo "<p>Rows.. if any:<br>";
// loop and display 1st col of table contents for ($i=0;$i < $rowCount; $i ) { $rsRow = mysql_fetch_array($rs); echo "<br>".$rsRow[0]; }
Skip to site navigation