FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » about php connection string
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
about php connection string [message #180229] Fri, 01 February 2013 07:47 Go to next message
amitjaluf is currently offline  amitjaluf
Messages: 5
Registered: February 2013
Karma: 0
Junior Member
Hello All
i am writing a connection string to connect database to the web page but when i run this with Firefox it shows Nothing. I am using Linux(Debian) on machine.

here is the code can anyone help me where i am wrong.

<?php
$db=mysql_connect("localhost","xyz","");
mysql_select_db("mysql",$db);
$rs=mysql_query("select * from emp",$db);
printf("User: %s\n",mysql_result($rs,0,"Ename"));
?>

and the other thing is when i save the .php file in "/var/www" its show me message Permission denied so where i have to put these files(Project) where from i can run.
Re: about php connection string [message #180230 is a reply to message #180229] Fri, 01 February 2013 11:12 Go to previous messageGo to next message
Kim Andr Aker is currently offline  Kim Andr Aker
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
På Fri, 01 Feb 2013 08:47:36 +0100, skrev <amitjaluf(at)gmail(dot)com>:

> Hello All
> i am writing a connection string to connect database to the web page but
> when i run this with Firefox it shows Nothing. I am using Linux(Debian)
> on machine.
>
> here is the code can anyone help me where i am wrong.
>
> <?php
> $db=mysql_connect("localhost","xyz","");
> mysql_select_db("mysql",$db);
> $rs=mysql_query("select * from emp",$db);
> printf("User: %s\n",mysql_result($rs,0,"Ename"));
> ?>

First, what do you see if you view the page source in Firefox? Do you see
your original PHP code, or is it just blank? If you see PHP code, it would
mean that your server (Apache, nginx, etc) is not configured to process
PHP code.

Second, does the database user you use to connect with actually have
access to the database you're selecting?

If you don't see PHP code in your page source, you might have errors in
your query or database connection. To see the errors, I suggest you
temporarily enable error reporting to see any hidden error messages. You
can do this in runtime by putting these two lines at the top of your first
<?php code block:

ini_set('display_errors', 'stdout'); // if you're using PHP older than
5.2.4, use '1' instead of 'stdout'
error_reporting(E_ALL);

Since there aren't any syntax errors in the script you pasted above, this
should output all error messages (even notices) to your HTML document.

> and the other thing is when i save the .php file in "/var/www" its show
> me message Permission denied so where i have to put these files(Project)
> where from i can run.

Make sure the .php file is readable by all users ("chmod a+r filename.php"
from the command line, or right-click - File Permissions in FileZilla).
Also, it may be that the /var/www directory has been set to not be allowed
in the webserver configuration (if this is the case, though, even not
specifying a file name in the URL would give the "Permission denied").

--
Kim André Akerø
- kimandre(at)NOSPAMbetadome(dot)com
(remove NOSPAM to contact me directly)
Re: about php connection string [message #180231 is a reply to message #180230] Fri, 01 February 2013 11:29 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 01/02/13 11:12, Kim André Akerø wrote:
> På Fri, 01 Feb 2013 08:47:36 +0100, skrev <amitjaluf(at)gmail(dot)com>:
>
>> Hello All
>> i am writing a connection string to connect database to the web page
>> but when i run this with Firefox it shows Nothing. I am using
>> Linux(Debian) on machine.
>>
>> here is the code can anyone help me where i am wrong.
>>
>> <?php
>> $db=mysql_connect("localhost","xyz","");
>> mysql_select_db("mysql",$db);
>> $rs=mysql_query("select * from emp",$db);
>> printf("User: %s\n",mysql_result($rs,0,"Ename"));
>> ?>
>
> First, what do you see if you view the page source in Firefox? Do you
> see your original PHP code, or is it just blank? If you see PHP code, it
> would mean that your server (Apache, nginx, etc) is not configured to
> process PHP code.
>
> Second, does the database user you use to connect with actually have
> access to the database you're selecting?
>
> If you don't see PHP code in your page source, you might have errors in
> your query or database connection. To see the errors, I suggest you
> temporarily enable error reporting to see any hidden error messages. You
> can do this in runtime by putting these two lines at the top of your
> first <?php code block:

I found that later versions of mysql tend to default to NOT allowing
'localhost' but will accept '127.0.0.1'

>
> ini_set('display_errors', 'stdout'); // if you're using PHP older than
> 5.2.4, use '1' instead of 'stdout'
> error_reporting(E_ALL);
>
Or look in /var/log/apache2/error.log

> Since there aren't any syntax errors in the script you pasted above,
> this should output all error messages (even notices) to your HTML document.
>
>> and the other thing is when i save the .php file in "/var/www" its
>> show me message Permission denied so where i have to put these
>> files(Project) where from i can run.
>
> Make sure the .php file is readable by all users ("chmod a+r
> filename.php" from the command line, or right-click - File Permissions
> in FileZilla). Also, it may be that the /var/www directory has been set
> to not be allowed in the webserver configuration (if this is the case,
> though, even not specifying a file name in the URL would give the
> "Permission denied").
>

in general the apache server needs read permission.

I generally fix that by working out what group apache is in, and
sertting sticky bits on group attributes in /var/www directories, so
all files belonging to the www-data group. Unless the file doesn't have
GROUP read perms, which is rare, that means apache can read it.

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: about php connection string [message #180233 is a reply to message #180231] Fri, 01 February 2013 13:46 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/1/2013 6:29 AM, The Natural Philosopher wrote:
> On 01/02/13 11:12, Kim André Akerø wrote:
>> På Fri, 01 Feb 2013 08:47:36 +0100, skrev <amitjaluf(at)gmail(dot)com>:
>>
>>> Hello All
>>> i am writing a connection string to connect database to the web page
>>> but when i run this with Firefox it shows Nothing. I am using
>>> Linux(Debian) on machine.
>>>
>>> here is the code can anyone help me where i am wrong.
>>>
>>> <?php
>>> $db=mysql_connect("localhost","xyz","");
>>> mysql_select_db("mysql",$db);
>>> $rs=mysql_query("select * from emp",$db);
>>> printf("User: %s\n",mysql_result($rs,0,"Ename"));
>>> ?>
>>
>> First, what do you see if you view the page source in Firefox? Do you
>> see your original PHP code, or is it just blank? If you see PHP code, it
>> would mean that your server (Apache, nginx, etc) is not configured to
>> process PHP code.
>>
>> Second, does the database user you use to connect with actually have
>> access to the database you're selecting?
>>
>> If you don't see PHP code in your page source, you might have errors in
>> your query or database connection. To see the errors, I suggest you
>> temporarily enable error reporting to see any hidden error messages. You
>> can do this in runtime by putting these two lines at the top of your
>> first <?php code block:
>
> I found that later versions of mysql tend to default to NOT allowing
> 'localhost' but will accept '127.0.0.1'
>

Then you screwed up your configuration (I'm not surprised). 'localhost'
is valid in all versions of MySQL.

>>
>> ini_set('display_errors', 'stdout'); // if you're using PHP older than
>> 5.2.4, use '1' instead of 'stdout'
>> error_reporting(E_ALL);
>>
> Or look in /var/log/apache2/error.log
>

Which is only valid if errors are being logged.

>> Since there aren't any syntax errors in the script you pasted above,
>> this should output all error messages (even notices) to your HTML
>> document.
>>
>>> and the other thing is when i save the .php file in "/var/www" its
>>> show me message Permission denied so where i have to put these
>>> files(Project) where from i can run.
>>
>> Make sure the .php file is readable by all users ("chmod a+r
>> filename.php" from the command line, or right-click - File Permissions
>> in FileZilla). Also, it may be that the /var/www directory has been set
>> to not be allowed in the webserver configuration (if this is the case,
>> though, even not specifying a file name in the URL would give the
>> "Permission denied").
>>
>
> in general the apache server needs read permission.
>
> I generally fix that by working out what group apache is in, and
> sertting sticky bits on group attributes in /var/www directories, so
> all files belonging to the www-data group. Unless the file doesn't have
> GROUP read perms, which is rare, that means apache can read it.
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: about php connection string [message #180235 is a reply to message #180231] Fri, 01 February 2013 14:55 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Fri, 01 Feb 2013 11:29:30 +0000, The Natural Philosopher wrote:
> On 01/02/13 11:12, Kim Andr?? Aker?? wrote:
>> P?? Fri, 01 Feb 2013 08:47:36 +0100, skrev <amitjaluf(at)gmail(dot)com>:
>>
>>> Hello All
>>> i am writing a connection string to connect database to the web page
>>> but when i run this with Firefox it shows Nothing. I am using
>>> Linux(Debian) on machine.
>>>
>>> here is the code can anyone help me where i am wrong.
>>>
>>> <?php
>>> $db=mysql_connect("localhost","xyz","");
>>> mysql_select_db("mysql",$db);
>>> $rs=mysql_query("select * from emp",$db);
>>> printf("User: %s\n",mysql_result($rs,0,"Ename"));
>>> ?>
>>
>> First, what do you see if you view the page source in Firefox? Do you
>> see your original PHP code, or is it just blank? If you see PHP code, it
>> would mean that your server (Apache, nginx, etc) is not configured to
>> process PHP code.
>>
>> Second, does the database user you use to connect with actually have
>> access to the database you're selecting?
>>
>> If you don't see PHP code in your page source, you might have errors in
>> your query or database connection. To see the errors, I suggest you
>> temporarily enable error reporting to see any hidden error messages. You
>> can do this in runtime by putting these two lines at the top of your
>> first <?php code block:
>
> I found that later versions of mysql tend to default to NOT allowing
> 'localhost' but will accept '127.0.0.1'

#1 newbie trap. "localhost" is NOT A NETWORK CONNECTION to mysql.
"localhost" is a OS socket or named pipe connection, depending on OS.

--
Cunningham's First Law:
Any sufficiently complex deterministic system will exhibit
non-deterministic behaviour.
Re: about php connection string [message #180291 is a reply to message #180230] Mon, 04 February 2013 03:41 Go to previous message
amitjaluf is currently offline  amitjaluf
Messages: 5
Registered: February 2013
Karma: 0
Junior Member
Thanks Kim for the advice
the error handling work's here
it shows the error in the particular line
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to get data for website pages..
Next Topic: Hot list for BA/QA, BA – Insurance, Embedded Engineer & Technical BM
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Dec 03 17:59:29 GMT 2024

Total time taken to generate the page: 0.02017 seconds