last_trace Posted December 16, 2006 Share Posted December 16, 2006 Okay, My website(dev area only, not viewable by public) works fine right now except I'm not sure that it is done correctly.I'm using Smarty as my main template engine.My site map is: htdocs----------------------------index.php--.htaccess--/cache (smarty folder)--/configs (smarty folder)--/inc------- --main.php (settings, configuration, etc.) --mysql.class.php (mysql class, does NOT call/start the class) --funcs.php (misc functions on the site.) --navigation.php (for my mod_rewrite/navigation,etc)---------/libs (smarty folder)--/templates (smarty folder) (holds index.tpl, register.tpl, etc, just the template designs)------- --/code (this is a folder that I created that holds the code for register,etc, pages that need php code.)---------/templates_c (smarty folder)My index.php calls my mysql class and all of the files in "/templates/code/" folder call it also.I don't understand why I have to call this every time.Here's a map below (key: -> means display)index.php -> index.tpl -> code/index.phpWhy do I have to call the mysql connection both in index.php and index.php in the code folder?Any Ideas? Quote Link to comment Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 [quote]Why do I have to call the mysql connection both in index.php and index.php in the code folder?[/quote]You shouldn't have to unless you have specifically named your connection resource. Quote Link to comment Share on other sites More sharing options...
last_trace Posted December 16, 2006 Author Share Posted December 16, 2006 What do you mean by naming my connection resource? Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 mysql_connect returns a connection resource. You can save this in a variable, eg;[code]<?php $cn = mysql_connect();?>[/code]Now, mysql_query optionally allows you to specify which connection resource to use. eg;[code]<?php mysql_query($sql,$cn);?>[/code]Hence, you can have multiple connections to mutilple databases. However, leaving second (and optional) argument out of mysql_query() it will automatically use the last connection opened (the desired effect when using one database).Are you explicitly setting this argument? Are you setting it the same each time? Quote Link to comment Share on other sites More sharing options...
last_trace Posted December 17, 2006 Author Share Posted December 17, 2006 Yes, It's using the same database, and I'm using the same exact call every time.I figured by including it on index.php (the main page which shows up when you access the website) it would work throughout all of the pages called from that page.[code]$db = new MySql_conn;$db->connect('localhost', 'username', 'password', 'database');[/code]is what I'm calling every time. Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 If your not using th enative mysql_* functions anything could be happening. Real hard to tell without seeing some code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.