SkipHuffman has asked for the wisdom of the Perl Monks concerning the following question:

Self agrandizing whine

I know that this is not precisely perl, but I hope that one of you wise people would kick me in the head and point me where I need to be.

Useless background

I am writing an application for a website. Simple push up a form, read parameters, write to database, read from database, write dynamic webpage stuff.

I have it working just fine on my development system. Now I need to push it up to the remote hosted site.

Once there, the application runs without apparent error, but I don't think it is updating the database properly.

The actual question

On my development system, I would be checking my database inserts by using mysql to check the database directly, how do I do this on a site where I have limited command line access?

Skip
  • Comment on Database access on your site, or "Where the hell is mysql?"

Replies are listed 'Best First'.
Re: Database access on your site, or "Where the hell is mysql?"
by jZed (Prior) on Oct 01, 2005 at 16:44 UTC
    The answer would appear to be: use SELECT statements to query the database and see if it contains what you expect it to (but perhaps I'm missing part of your requirements). You can issue these SELECTs the same way you issue your INSERTS (e.g. through a web front end) or else you can use a command line tool. If you don't have access to MySQL's native command line tool, you can try dbish, in the DBI::Shell distribution which provides a generic command line tool for all DBI accessible databases and can be installed by a non-root user in any directory.

      Yes, select statements are what I am using in the code itself, but for the debug portion, I want to see what my insert did. The way I usually do that is to use the mysql client and run the statement interactively.

      I will look at dbish, that might be exactly what I need.

      Skip
Re: Database access on your site, or "Where the hell is mysql?"
by pg (Canon) on Oct 01, 2005 at 16:51 UTC
    "Once there, the application runs without apparent error, but I don't think it is updating the database properly."

    This is a good indication that you are not checking return code and SQLCODE in your code. Better fix the code. For any database operation, always always check the SQLCODE. For any perl function call, always check return code.

    You must have some code similar to this:

    $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password);

    Change $hostname to where your MySQl resides. Make it configurable.

    Also you have to configure mysql so that it allows remote access. (I guess your development box probably is the same where mysql sits.)

      You are correct, my error checking is quite inadequete. I intend for it to be fixed "properly" at some point. But for the moment I just want to get the general function working.

      My intention with this is for it to be a base/straw man so that I can hire a couple of more experienced programmers to work with me to make it correct. Thus my error checking is lousy.

      I do have the database connection information. And I believe the connection is working correctly. It is just the inserts that I think may be failing.

      My development box has MySQL installed locally and all the inserts, selects and all work fine with everything local. When I upload to my hosting provider, I am seeing some things that look like they are working, but I don't think it is inserting into the database, or perhaps I am not selecting back from the database correctly. I would like to try to figure out which. If I were on my development system, I would just pull up the mysql client and run some selects from there, but I do not seem to have that client available to me at my hosting provider. Is there an common way to get the equivalent of a mysql client on a remote database?

      I know that I have a lot of slop in the code. I am doing it as a demonstration so that I can hire a more experienced programmer to crawl in and fix it. Its easier to explain what I am trying to do by doing it than by waving my hands around. Thanks

      Skip
        Howdy!

        Putting in adequate error checking is part and parcel of getting the general function working. If your code can't tell if the database actions worked or not, it's broken. At the least, you can't demonstrate that it isn't broken.

        You could try setting RaiseError to true, which will make it blow up when a DBI error occurs. That will be better than nothing, especially if you couple that with CGI::FatalsToBrowser (or whatever that bit is that makes the CGI error messages go to the browser instead of the local error log where you might never see them.

        yours,
        Michael
Re: Database access on your site, or "Where the hell is mysql?"
by graff (Chancellor) on Oct 01, 2005 at 21:27 UTC
    If you have mysql installed and running on your development system, and mysql is installed and running on the remote system, and the development box is able to ping the remote box, then you should be able to connect to the remote database using the "mysql" command line on your dev system:
    mysql -h remote.host.name -u useraccount -ppassword dbname
    where the useraccount, password and dbname are whatever you're using for the db connection on the remote version of your website. This sort of remote server access with mysql is very common.

      That sounds like exactly what I need, but I suspect that I am blocked from that access. Here is what I tried:

      mysql -h mysql2.america.net -u flying -p***** databasename

      And I get no response for quite some time. mysql appears to be waiting for something, it just sits and waits. Eventually it times out and I get "ERROR 2003 (HY000): Can't connect to MySQL server on 'mysql2.america.net' (110)" Thanks though! I guess I need to get the php admin working.

      Skip
Re: Database access on your site, or "Where the hell is mysql?"
by davidrw (Prior) on Oct 01, 2005 at 20:03 UTC
    If you don't have access to the commandline mysql utility, a very good alternative is phpMyAdmin -- if your host has php setup it's pretty much a drop-in install (you just set connection info in a config file).

      Looks very useful! Bit of a learning curve though. I am looking into it. Thanks!

      Skip

      Ok, installed and working. Looks very useful. I better secure it pretty quickly though. I wasn't expecting to have to put something web based on there. Thanks!

      Skip