View Full Version : Just starting with PHP and MySql
krieves
01-16-2004, 12:24 PM
This will seem like a stupid question, but I cannot get a simple PHP script to return any results. I created a database (kentest) and table (contactinfo). The table has one record that contains four fields. I'm just trying to return a value from the "number" field in the table. What am I doing wrong? Here is the page:
<html>
<head>
</head>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("kentest",$db);
$result = mysql_query("select number from contactinfo",$db);
printf("Number: %s \n", mysql_result($result,0,"number"));
echo "
";
echo "Test";
?>
</body>
</html>
Also, is there a trick to debugging PHP? I'm not getting any errors, so I can't tell what is going wrong. Any suggestions are welcome and thanks for your patience on a simple question.
bobrob
01-16-2004, 01:43 PM
Krieves,
Try this:
$db = mysql_connect("localhost", "root") or die("Could not connect: " . mysql_error());
instead of your connect, just to make sure you are getting a connection to the mysql server.
Might shed some light... in fact, I usually send the password as well:
$db = mysql_connect("localhost", "root", "<mypassword>") or die("Could not connect: " . mysql_error());
But it may not be required, depending on your grants in mysql.
Hope this helps! (new to the PHP part myself)
Bob
jalal
01-16-2004, 03:00 PM
Also, is there a trick to debugging PHP? I'm not getting any errors, so I can't tell what is going wrong. Any suggestions are welcome and thanks for your patience on a simple question.
Error display is turned off by default, but you can turn it on. You need to edit the /usr/local/lib/php.ini file and change the line:
display_errors off
and turn it on.
There is also error logging available, look for:
log_errors off
Read the comments. For a production server, turn the display_errors OFF, they are a possible security risk.
Restart Apache after changing php.ini
HTH
wildjokerdesign
01-16-2004, 06:08 PM
jalal,
Isn't /etc/php.ini a sym link to /usr/local/lib/php.ini ? If you where downloading, editing and then uploading via FTP would you do that with the file in /usr/local/lib/php.ini ?
jalal
01-17-2004, 03:02 AM
Absolutely correct Shawn.
The file to edit is /usr/local/lib/php.ini
Thanx
wildjokerdesign
01-17-2004, 06:16 AM
Also I thought I might mention in case someone reads this and decides to alter the file for other reasons then simply logging or error reporting that I think this is a file that could get over written by WestHost if they happen to do an update or modification to php. It would be a good idea to keep a backup on your local of the modified version in case this happened.
krieves
01-17-2004, 06:53 AM
Thanks everyone. Bobrob, yup the password works. I thought I had permissions set so that anyone could access the database. I guess not. :wink:
I'm still looking for the PHP.ini file. Hmm, where could it be hiding...
wildjokerdesign
01-17-2004, 08:19 AM
If you are looking via FTP it is in /usr/local/lib/php.ini and you need to scroll down if it is like my program becuase it is at the bottom. If it is not there I am not sure what to say except check through your Site Manager that you have all the correct Apps installed.
jalal
01-17-2004, 09:04 AM
Should you *really* not find it....
Create a file in your web root called phpinfo.php containing:
<?php
phpinfo();
?>
and call that with your web browser, that will show you all the settings for apache and php.
wildjokerdesign
01-17-2004, 07:21 PM
Thanks jalal, I really wish I would remember that one. :)
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.