Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mysql broken with lilurl?

Posted on 2009-07-04
7
Medium Priority
?
2,517 Views
Last Modified: 2012-05-07
Set up lilurl, with a lamp stack on ubuntu 8.10 intrepid.  Had some issues earlier and used a softlink to fix the link issues.

now when entering a url to shorten I get the errors listed below.

Not familiar with this setup, and wondering why it's broken.

Any ideas?
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /etc/lilurl/includes/lilurl.php on line 19
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /etc/lilurl/includes/lilurl.php on line 73
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /etc/lilurl/includes/lilurl.php on line 123

Open in new window

0
Comment
Question by:Illyankesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:Illyankesh
ID: 24776348
This is the url configuration file, and he below comment is the offending /etc/iilurl/includs/lilurl.php file.
I used heidi to import the correct db as per the instructions, however I used a softlink instead of the htaccess file.  Couldn't get the htaccess file to work.

lilURL 0.1.1 http://lilurl.sourceforge.net

lilURL is a simple PHP/MySQL app that works basically like tinyurl.com,
allowing you to create shortcuts on your own server.

-----------------------------------------------------------------------

To install:

1. Create a MySQL database and user for lilURL.

2. Import the lilurl.sql file:

      (( like so:

         mysql -u <lilurl_user> -p <lilurl_db> < lilurl.sql

      ))

3. Edit the configuration file includes/conf.php to suit your needs.

4. Set up mod_rewrite, if necessary

      (( a .htaccess file with the lines:

         RewriteEngine On
         RewriteRule (.*) index.php

        should suffice ))

5. Buy 15 donuts and eat them all in one sitting.

<?php /* lilurl.php ( lilURL class file ) */
 
class lilURL
{
        // constructor
        function lilURL()
        {
                // open mysql connection
                mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die('Could not connect to database');
                mysql_select_db(MYSQL_DB) or die('Could not select database');
        }
 
        // return the id for a given url (or -1 if the url doesn't exist)
        function get_id($url)
        {
                $q = 'SELECT id FROM '.URL_TABLE.' WHERE (url="'.$url.'")';
                $result = mysql_query($q);
 
                if ( mysql_num_rows($result) )
                {
                        $row = mysql_fetch_array($result);
                        return $row['id'];
                }
                else
                {
                        return -1;
                }
        }
 
        // return the url for a given id (or -1 if the id doesn't exist)
        function get_url($id)
        {
                $q = 'SELECT url FROM '.URL_TABLE.' WHERE (id="'.$id.'")';
                $result = mysql_query($q);
 
                if ( mysql_num_rows($result) )
                {
                        $row = mysql_fetch_array($result);
                        return $row['url'];
                }
                else
                {
                        return -1;
                }
        }
 
        // add a url to the database
        function add_url($url)
        {
                // check to see if the url's already in there
                // check to see if the url's already in there
                $id = $this->get_id($url);
 
                // if it is, return true
                if ( $id != -1 )
                {
                        return true;
                }
                else // otherwise, put it in
                {
                        $id = $this->get_next_id($this->get_last_id());
                        $q = 'INSERT INTO '.URL_TABLE.' (id, url, date) VALUES ("'.$id.'", "'.$url.'", NOW())';
 
                        return mysql_query($q);
                }
        }
 
        // return the most recent id (or -1 if no ids exist)
        function get_last_id()
        {
                $q = 'SELECT id FROM '.URL_TABLE.' ORDER BY date DESC LIMIT 1';
                $result = mysql_query($q);
 
                if ( mysql_num_rows($result) )
                {
                        $row = mysql_fetch_array($result);
                        return $row['id'];
                }
                else
                {
                        return -1;
                }
        }
 
        // return the next id
        function get_next_id($last_id)
        {
 
                // if the last id is -1 (non-existant), start at the begining with 0
                if ( $last_id == -1 )
                {
                        $next_id = 0;
                }
                else
                {
                        // loop through the id string until we find a character to increment
                        for ( $x = 1; $x <= strlen($last_id); $x++ )
                        {
                                $pos = strlen($last_id) - $x;
 
                                if ( $last_id[$pos] != 'z' )
                                {
                                        $next_id = $this->increment_id($last_id, $pos);
                                        break; // <- kill the for loop once we've found our char
                                }
                        }
 
                        // if every character was already at its max value (z),
                        // append another character to the string
                        if ( !isSet($next_id) )
                        {
                                $next_id = $this->append_id($last_id);
                        }
                }
 
                // check to see if the $next_id we made already exists, and if it does,
                // loop the function until we find one that doesn't
                //
                // (this is basically a failsafe to get around the potential dangers of
                //  my kludgey use of a timestamp to pick the most recent id)
                $q = 'SELECT id FROM '.URL_TABLE.' WHERE (id="'.$next_id.'")';
                $result = mysql_query($q);
 
                if ( mysql_num_rows($result) )
                {
                        $next_id = $this->get_next_id($next_id);
                }
 
                return $next_id;
        }
 
        // make every character in the string 0, and then add an additional 0 to that
 
        function append_id($id)
        {
                for ( $x = 0; $x < strlen($id); $x++ )
                {
                        $id[$x] = 0;
                }
 
                $id .= 0;
 
                return $id;
        }
 
        // increment a character to the next alphanumeric value and return the modified id
        function increment_id($id, $pos)
        {
                $char = $id[$pos];
 
                // add 1 to numeric values
                if ( is_numeric($char) )
                {
                        if ( $char < 9 )
                        {
                                $new_char = $char + 1;
                        }
                        else // if we're at 9, it's time to move to the alphabet
                        {
                                $new_char = 'a';
 
               }
                else // move it up the alphabet
                {
                        $new_char = chr(ord($char) + 1);
                }
 
                $id[$pos] = $new_char;
 
                // set all characters after the one we're modifying to 0
                if ( $pos != (strlen($id) - 1) )
                {
                        for ( $x = ($pos + 1); $x < strlen($id); $x++ )
                        {
                                $id[$x] = 0;
                        }
                }
 
                return $id;
        }
 
}
 
?>

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24776587
The errors indicate that the database is not set up correctly. Check that the settings in conf.php are correct, modify them if needed.
0
 

Author Comment

by:Illyankesh
ID: 24777882
Imported the provided lilurl.sql file using heidi to the correct database still same error.  which conf.php file needs to be checked?
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

Author Comment

by:Illyankesh
ID: 24777891
Fixed.
Combination of errors mostly user
The mysql database imprint had not been executed, therefore the databse file hadn't been completely built and saved which was causing the errors
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 1500 total points
ID: 24777953
>> which conf.php file needs to be checked?

lilurl/includes/conf.php

>> Fixed.

Great! :)
0
 

Author Comment

by:Illyankesh
ID: 24789545
Yep...now for one last boggle.  the links that are produced by the lilurl are broken?  Thoughts?


Not Found
 
The requested URL /1 was not found on this server.
Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch Server at lsm.mobi Port 80
 
 
Now the short urls that are being created...do they have to be native to this server?  Or should I just be able to take a random long url off of any old website, and then click on the link that lilurl spits out?

Open in new window

0
 

Author Closing Comment

by:Illyankesh
ID: 31599740
The primary error was caused by the incomplete upload of the lilurl mysql file.  This was the root of the errors that were being encountered.  Heidi sql has an execute query switch that has to be entered once a data file is uploaded.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question