I should've checked the assumption.

A little strange though for a scripting language. I'd say, since
default behaviour of mysql_* functions is to assume the last opened
link when a parameter is not passed, and since default behaviour is to
evaluate null, false and 0 the same, mysql_* functions should issue a
warning when a not valid link is passed but still use the last opened
link (in that logic, null should also generate a warning though). I'm
guessing the reason is that mysql_connect returns false when it fails,
but i can't see a reason why an undefined variable cannot be used.

All that and I don't remember what it was for.

On Fri, Jun 20, 2008 at 1:57 AM, Chris <[EMAIL PROTECTED]> wrote:
>
>> [new code]
>> if (!mysql_connect($a, $b, $c)) return;
>>
>> if (!mysql_select_db($dbname)) return;
>>
>> $res = mysql_query("SELECT * FROM manual;", $link);
>> [/new code]
>
>
> Isn't going to work because $link is not defined and definitely not a
> resource like mysql_query expects.
>
>> OR, optionally, to surpress the warnings:
>>
>> [new code]
>> if (!mysql_connect($a, $b, $c)) return;
>>
>> $link = null;
>>
>> if (!mysql_select_db($dbname)) return;
>>
>> $res = mysql_query("SELECT * FROM manual;", $link);
>> [/new code]
>
> Isn't going to work because mysql_query needs a resource to connect to.
> You've defined $link as null.
>
> $ cat test.php
> <?php
> $user = 'my_db_user';
> $pass = 'my_pass';
> $host = 'localhost';
> $db = 'my_db';
>
> error_reporting(E_ALL);
> ini_set('display_errors', true);
>
> if (!mysql_connect($host, $user, $pass)) {
>        die("unable to connect");
> }
>
> if (!mysql_select_db($db)) {
>        die("unable to choose db");
> }
>
> $link = null;
> $res = mysql_query('select version() as version', $link);
> while ($row = mysql_fetch_assoc($res)) {
>        print_r($row);
> }
>
>
> $ php test.php
>
> Warning: mysql_query(): supplied argument is not a valid MySQL-Link
> resource in /path/to/test.php on line 19
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
> result resource in /path/to/test.php on line 20
>
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to