Does this work? Even with database connections?
Code:require("../file.php");
Printable View
Does this work? Even with database connections?
Code:require("../file.php");
You mean if the required script is accessing a database?
Yes. I made a second script and require the one I posted in your other thread there:
And it gave me identical results.PHP Code:<?php
require('dbtest.php');
?>
Require is just like and include, it will act as if the included file is part of the existing script. The only difference from an include is that it will give a fatal error instead of a warning on an error.
Hum... note that the require uses a relative url syntax. I'm not getting any errors, but i'm also not retrieving any data.
Relative url syntax works fine w/ require. How are you "not retrieving any data"? Some more details might help us diagnose your problem.
I'm working on an admin page that has lists of most of my tables, etc. and with each table, I have put a form for adding a post to each table. Those queries work. However, I've also added queries that would pull all the records from my old database and update them to the new database. These queries do not work, even though i have triple checked the syntax (not necessarily 100% foolproof, but ya know). I seem to get an error that the fields in the second database and table could not be found. Could it be that since the tables are named the same that MySQL is confused and I somehow need to specify which database in the query, not just the database connection?
No, you woudn't specify the database in the query. Nor the connection. You specify the database with the mysql_select_db function.
Maybe if you posted the code that is giving you a hard time it would be a little easier to help you.
Again, whether you are using two DB connections or one, you need to select the current database with mysql_select_db directly prior to the query.
Hmmmm... I was using a function that created a connection and automatically selected the database per the connection. I'll tinker...
Not sure how we ended up over here...
CODE:
Code:if(!$old_result = mysql_query("SELECT * FROM table",database_connection("localhost","php","php","old_db")))
{
error_message("Check old database names.\n");
exit();
}
while($old_record = mysql_fetch_object($old_result))
{
if(!mysql_query("INSERT record(fields...) VALUES('$old_fields')",$database_link))
{
error_message("Check new database names.\n");
exit();
}
}
Crushing Success (all around) by not using my function and actively using the select_db function.
MUCH THANKS TO YOU BOTH!
I've been coding all day [this is your brain on PHP].
Nice, glad to hear you got it working :)