LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-09-2006, 06:10 PM   #1
jun_tuko
Member
 
Registered: Oct 2005
Location: Seattle, WA
Distribution: Fedora Core 4
Posts: 67

Rep: Reputation: 15
Need help on PHP connecting to MySQL (Fedora Core 4, Apache)


hello gurus,

i have a webserver running using apache and php (works fine). i'm trying to integrate and use mysql to my system. i copied a php script from a book to test my php-apache-mysql connection but its not giving me the expected output.

below is the code. you will notice that i placed "echo" before and after mysql_connect. it showed "connecting" on the browser, but seemed to hang because it does not show "after connection". the fields are manually entered in mysql.

here's the code:

///// database_connection.php
<?php
$dbUser = 'test_user';
$dbPass = 'test_pass';
$dbName = 'my_test';
$dbHost = 'localhost';

echo "Connecting";

$sql = mysql_connect($dbHost, $dbUser, $dbPass)
or die (mysql_error());

echo "After Connection";

mysql_select_db($dbName, $sql) or die (mysql_error());
?>

///// database_insert.php
<?php
include ('database_connection.php');

for ($i = 0; $i <= 50; $i++)
{
if($i % 2)
{
$data = $i.' -Odd Result';
}
else {
$data = $i.' -Even Result';
}

mysql_query("INSERT INTO my_table (my_value, my_date)
VALUES ('$data', now())") or die (mysql_error());
echo "Inserting: $data<br />";
}
echo "Done<br />";
?>

where does mysql put its errors by the way?

thanks guys!

jun
 
Old 01-09-2006, 06:59 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
The way PHP reports errors is controlled by the ini file. The file does quite a good job of explaining it. The options are errors can be sent to the screen, errors can be sent to stderr, stderr can be overridden by a named file (ensure that apache has write access to that file). Also you can control the level of errors that are reported. The best thing is to look at the ini file for more info.

graeme.
 
Old 01-09-2006, 07:05 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You may want to consider changing your code as follows, for a chance of a little more information:

PHP Code:
echo "Connecting";

$sql mysql_connect($dbHost$dbUser$dbPass)
or die (
"Failed to connect: "+mysql_error());

echo 
"After Connection";

mysql_select_db($dbName$sql) or die ("Failed to select db "+mysql_error()); 
graeme
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora Core 3 And PHP + Apache xbigs Fedora 1 12-17-2005 07:24 AM
uninstaling php and apache on fedora core 3 mhatre kedar Linux - Networking 1 03-20-2005 04:58 AM
Apache PhP MSQL - if they come with fedora core 1 where are they Virtualhate Linux - Newbie 1 05-16-2004 08:33 PM
mysql and connecting from php on apache with moregroupware seriv Linux - Newbie 1 07-25-2003 10:57 AM
mysql and connecting from php on apache with moregroupware seriv Linux - Software 1 07-25-2003 08:11 AM


All times are GMT -5. The time now is 04:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration