On Thu, 29 Nov 2001, anandakkumar araskumar wrote:

> Hi all
> Iam new to php and iam learning that from scratch.I
> came across a problem in connecting mysql from php
> script.I run php in windows2000 under IIS configured
> to personal web server.I have installed mysql
> with server and client and both are running in the
> same machine(ofcourse, i can you use the ipaddress of
> localhost).I didn't set any username or password with
> mysql.
>
> This is my php script:
> $link=mysql_connect("localhost");
> if($link)
> die("Couldn't connect to mysql".mysql_error() );

Perhaps you meant if(!$link) ...
Notice the not ! operand. If a link is established then the $link PHP
variable will no longer hold the empty string. In PHP all varaibles
are automatically initialized to hold an empty string which can also
be used interchangeably with the boolean false value.

The standard way of connecting is:

   $link = mysql_connect("$db_host", "$db_user", "$db_pass")
      OR die("Could not connect to database server.");

Here the stuff after OR is executed only if mysql_connect returns false
which is the way the C || operator works.

Regards,

Neil


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to