Jump to content

Need some help.


last_trace

Recommended Posts

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.php

Why do I have to call the mysql connection both in index.php and index.php in the code folder?

Any Ideas?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.