[thelist] mysql_query + php

shawn allen shawn at alterior.net
Tue Feb 25 14:04:01 CST 2003


quoth Andrew Maynes:
> I posted that in haste it is the whole connection thing you are right
>
> It worked when I took out "$DBName", and replaced it with ->
>
> mysql_select_db("$DBName");

BTW, this whole "$foo" thing is really ticking me off... There's no need
to incur the overhead of variable interpolation unless you need to embed
the value in another string! In this case,

  mysql_select_db($DBName);

works just as well, without having PHP go to the trouble of parsing the
string for interpolated variables.

If you're concerned about the variable's type, you should either a) cast
it, a la `(string) $DBName', or use one of the is_*() functions to
verify the type before using it as a function argument. So, if $DBName
really *must* be a string, use:

  mysql_select_db((string) $DBName);

or:

  if (is_string($DBName))
      mysql_select_db($DBName);
  else
      die("DBName is not a string!\n"); // or something

Thanks,

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list