Help Me With PHP, CGI & MySQL!

May 14th, 2008 · 1 Comment

I just got this email in my mailbox and I figured it could be useful to other people, so I decided to answer it here. Here it goes:

Hello Stephane

Thanks for the offer.

What I am trying to do is this:

I got a new win 2008 server, and am trying to install different services on it. I have done the php part, and my phpinfo script works nicely.Previously in win 2003 server, I had used php-cgi.exe for installing the cgi test script. I used the same exe here, but otherwise followed your ISAPI PHP installation steps.My code for a test cgi script is:

#!C:\php\php-cgi.exe -wc
#/usr/local/bin/perl
# simple Hello World script
print “Content-type: text/plain\n\n”;
print ‘Hello World!’;

This code on the browser just brings up all the source code, except the first line.

Secondly, my mysql server instance configuration gives me the error: Error No: 1146. Table ‘mysql.servers doesn’t exist. When I check my php info page, it shows the proper mysqli box as on your tutorial. So I don’t know whether mysql is working or not. I can access mysql from command prompt, and I get 2 databases - mysql and test. Mysql db has these tables: columns_priv, db, event, func, general_log, help_category, help_keyword, help_relation, help_topic, host, plugin, proc, procs_priv, slow_log, tables_priv, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type and user. In all 21 tables. The test db comes up empty.

I would appreciate your help on these 2 issues.

Ok well first of all about the test cgi script. You either have to use PHP or Perl but you can’t use both. They are two different programming languages. The second thing is how you named your file. The file extension determine which language interpreter (PHP or Perl) will be invoked.

If you want to use PHP, you will need to use the .php extension but if you want to use a Perl script, then you’ll have to use the .pl extension. You’ll also need to have Perl installed if you want to use Perl scripts.

Also, there is no need to send the “Content-type” header instruction just to test CGI functionnality.

As for the MySQL issue, I would need more detail like where do you get this error message?

If you can access MySQL through command line then the service itself is working fine but it doesn’t mean your web server can interact with it. The two databases you see there are created upon MySQL installation. The test database is not necessary but the one named “mysql” is vital to MySQL. Don’t mess with it.

Instead you should download and install the MySQL GUI tools from here. It will allow you to manage databases and users. Once you’ve created a new database and associated a user to it, use this PHP script to test connectivity:

<?php

if(!mysql_connect(’hostname’, ‘user’, ‘password’))
die(’Cannot connect to database server’);

if(!mysql_select_db(’database name’))
die(’Cannot select database’);
?>

Hope this helped! Feel free to comment my answer!

Got more questions about web hosting? Send me an email at info at thewebhostinghero.com!

Want to receive more tutorials and user experiences like this? Click here to subscribe.

1 response so far ↓

1. Response by : Stephane Brault on Jun 3, 2008 at 9:04 am

I was finally able to reproduce the error 1146.

This is caused by the MySQL Configuration Wizard not using the specified password. In this case you could leave the root password blank upon setup and change it afterward.

I have not had this issue with MySQL 5.0 though.

Leave a Comment




Posted in Articles | 1 Comment

Dedicated Servers
 
VPS
Website Hosting
 

Recent Comments

Recent Webmasters

Hosting Type :
Monthly Price :
Storage :
Transfer :
Sort By :
Search