Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Create a connection to the database
- $database = new mysqli('localhost', 'username', 'password', 'databasename') or die('Could not connect to database');
- // Increase the hitcounter by one
- $database->query('update hitcounter set hits = hits + 1') or init();
- // Do a mysql "search" to get the hitcounter
- $result = $database->query('select hits from hitcounter') or die('error selecting hitcounter');
- // Read the result
- if ($result = $result->fetch_assoc())
- {
- // Show the hitcount
- echo $result['hits'];
- }
- else init();
- // Called if the increase step fails
- function init()
- {
- global $database;
- // Could not increase hitcounter, probably the table doesn't exist
- $database->query('create table if not exists hitcounter ( hits int(11) not null )') or die('could not create table');
- $database->query('insert into hitcounter values(1)') or die('could not insert hitcounter');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement