0

I'm not sure what the problem is, I have a file called dbs.inc.php which contains the user/pass/database variables and mysql_connect(); statement. If I include("dbs.inc.php"); in a function the next line underneath it always has to be mysql_select_db($database); is that normal? Shouldn't the included variables be accessable until the function ends? Why does adding a few extra lines of code between the connect/select statements prevent the select from working?

Again:

include("dbs.inc.php");
mysql_select_db($database);

works. and if I do this:

include("dbs.inc.php");
$a = "123456";
mysql_select_db($database);

the mysql_select_db($database) will fail to select the database?

Binxalot
  • 41
  • 7
  • 5
    mysql_select_db is optional. It just sets the default database to use. You can still do absolute queries with `select dbname.tablename.fieldname ...` without ever doing a select_db. – Marc B Sep 17 '12 at 14:26
  • 2
    it shouldn't matter. there's no rule that says that mysql_select_db has to come right after the include statement. And stop using mysql_ functions. they are deprecated. Use PDO or if you must msqli_ – Vlad Balmos Sep 17 '12 at 14:27
  • 2
    Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/KJveJ). See the *[red box](http://goo.gl/GPmFd)*? Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/3gqF9) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/vFWnC). – John V. Sep 17 '12 at 14:37

0 Answers0