Archive for the "MySQL" Category

16
Jul

Ever wanted to create a simple hit counter for your site, but never had the chance to code it yourself? Then, you may simple use the code below — all hard coded by me, royalty-free. The code is used to teach non-techie people how to create PHP-MySQL-driven websites.

<?php
// connect to the MySQL server using 'localhost' as the server name, cPanel username & password
$con = mysql_connect("localhost","cpanelusername","password");
// check if the connection is established or not
if (!$con)
   {
      die('Could not connect: ' . mysql_error());
   }

// continue with the database processes if the connection is successful
else
   {
      // select the database you wish to connect to
      mysql_select_db("ctrdbase", $con);
      // go to the last record in your database table, this will also be the last number
      $result = mysql_query("SELECT * FROM counter_table ORDER BY ctr DESC LIMIT 1");
      $row = mysql_fetch_array($result);
      // store the last record to a variable
      $cctr = $row['ctr'];
      // declare a new variable that will do the addition thing
      $nctr = $cctr + 1;
      // store the updated counter to the database
      $sql = "INSERT INTO counter_table (ctr) VALUES ($nctr)";
      $dbupdate = mysql_query($sql);
      echo $nctr;
   }
mysql_close($con);
?>

Popularity: 29% [?]

17
Nov

Had you ever experienced exporting and importing a MySQL database? There should be no problem doing these simple tasks, thanks to PHPMyAdmin. But, if your database is big, say the one being used by a forums website with around 50 active users, it may be hard to import the MySQL database since it will take some time and you might encounter “timeouts” along the way (specially if your internet connection is not that fast enough to beat the timeout settings of the MySQL server).

The best way to import a MySQL database, if it is big (more than 10MB, is thru the command lines — SSH access is required. Simply execute the following command:

mysql --username=myusername --password=mypassword newmysqldb < oldmysqldb.sql

Where,  myusername is the MySQL Database User; mypassword is the MySQL Database User Password; newmysqldb is the name of the empty MySQL database; and the oldmysqldb.sql is the SQL file containing the exported database.

Now, sad to say, due to security concerns, most webhosting service providers doesn’t give SSH access to their clients. You may want to ask your webhosting service provider to do this on your behalf.

If your current webhosting service provider tells you that they cannot do it (either they do not know how to do it — the command is already above!; or they do not have SSH access), better think of transferring to another webhost (TurfSitePH.net is always here, hehehe), as they may just be a reseller of another company.

Popularity: 11% [?]


 Powered by Max Banner Ads