[Solved] Connecting to MySQL with an include file.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Abs
Forum Newbie
Posts: 7
Joined: Sat Jul 09, 2005 11:59 am
Location: Toronto, Canada

[Solved] Connecting to MySQL with an include file.

Post by Abs »

Hi. I'll admit that I'm pretty new to PHP, and that I only have limited experience with MySQL. I joined here hoping to learn more as I went along.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

Code: Select all

<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = &quote;localhost&quote;;
		$username = &quote;dbusername&quote;;
		$password = &quote;dbpassword&quote;;
		$database = &quote;dbname&quote;;

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
In the actual page that users see, here is the part where I try to connect to the database:

Code: Select all

<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
[client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I'm sorry if it seems a bit sloppy.g that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

Code: Select all

<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
In the actual page that users see, here is the part where I try to connect to the database:

Code: Select all

<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I'm sorry if it seems a bit sloppy.n from the include file
dbconnect()

# Set the query and run it
$query = "SELECT * FROM $db WHERE user='$user'";
$result = $dbh->query($query);
$row = $result->fetch_object($result);

# Print the results
echo $row->username;


Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
[client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I'm sorry if it seems a bit sloppy.lding a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

Code: Select all

<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
In the actual page that users see, here is the part where I try to connect to the database:

Code: Select all

<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I' include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

Code: Select all

<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
In the actual page that users see, here is the part where I try to connect to the database:

Code: Select all

<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searlogs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

Code: Select all

<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
In the actual page that users see, here is the part where I try to connect to the database:

Code: Select all

<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
Here is the error from the Apache log:

Code: Select all

&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Ath MySQL. I joined here hoping to learn more as I went along.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php[/code]

I've tried searching on Google for solutions, and It I'm pretty new to PHP, and that I only have limited experience with MySQL. I joined here hoping to learn more as I went along.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/plong.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]&lt;?php
	function dbconnect() {
		# Set the Connection Variables
		$host = &quote;localhost&quote;;
		$username = &quote;dbusername&quote;;
		$password = &quote;dbpassword&quote;;
		$database = &quote;dbname&quote;;

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php[/code]

I've tried searching on Google for solutions, and I've found alternates td almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php[/code]

I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really went along.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel along.

Right now I'm building a control panel type application for a website, and I need almost every page to connect to a database. I had the idea of putting the connection details into a function in an include file, and then just calling that function. Sadly, that doesn't work. When I check my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php[/code]

I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answerk my error logs in Apache I am told that $dbh does not exist.

Here is what I have in my include file:

[php]<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
[Fri Jul 08 22:48:40 2005] [error] [client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
[client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
[client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php[/code]

I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I'm sorry if it seems a bit sloppy.<?php
	function dbconnect() {
		# Set the Connection Variables
		$host = "localhost";
		$username = "dbusername";
		$password = "dbpassword";
		$database = "dbname";

		# Open the database
		@ $dbh = new mysqli($host, $username, $password, $database);

		# Check to see if connection failed. If true, print error page then exit.
		if (mysqli_connect_errno() ) {
			$errorhandling;
            exit;
		}
}
[/php]

In the actual page that users see, here is the part where I try to connect to the database:

[php]
<?php
         # Include file
         include('./include.php');
         
         # Run the function from the include file
         dbconnect()
 
         # Set the query and run it
         $query = "SELECT * FROM $db WHERE user='$user'";
         $result = $dbh->query($query);
         $row = $result->fetch_object($result);

         # Print the results
         echo $row->username;
[/php]

Here is the error from the Apache log:

[code]
&#1111;Fri Jul 08 22:48:40 2005] &#1111;error] &#1111;client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico
&#1111;client 127.0.0.1] PHP Notice:  Undefined variable: dbh in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
&#1111;client 127.0.0.1] PHP Fatal error:  Call to a member function query() on a non-object in C:\\Apache2\\htdocs\\controlpanel\\index.php on line 190, referer: http://localhost/controlpanel/index.php
I've tried searching on Google for solutions, and I've found alternates to what I am doing...However I'm posting here because I'd really just like to learn why what I'm doing is wrong.

I'd appreciate any answer!

Thanks in advance,

Abs

P.S.: Much of the connection code is from a book that I'm learning from, so I'm sorry if it seems a bit sloppy.
Last edited by Abs on Sat Jul 09, 2005 3:07 pm, edited 1 time in total.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Your $dbh is defined inside a function. $dbh does not exist outside that function. You should try and return $dbh.

Code: Select all

$dbh=dbconnect();
//...
//include
return $dph;
lude
return $dph;
u should try and return $dbh.

Code: Select all

$dbh=dbconnect();
//...
//include
return $dph;
ed inside a function. $dbh does not exist outside that function. You should try and return $dbh.

Code: Select all

$dbh=dbconnect();
//...
//include
return $dph;
dbconnect();
//...
//include
return $dph;

$dbh=dbconnect();
//...
//include
return $dph;
Abs
Forum Newbie
Posts: 7
Joined: Sat Jul 09, 2005 11:59 am
Location: Toronto, Canada

Post by Abs »

Hey wwwapu, thanks for the reply!

Because I'm new at this I have not really been able to figure out where I'm supposed to place things. My understanding of your code right now is that I am supposed to put

Code: Select all

$dbh=dbconnect();
into my index.php (the control panel), and

Code: Select all

return $dph //(typo?)
into my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Absto my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Abse right now is that I am supposed to put

Code: Select all

$dbh=dbconnect();
into my index.php (the control panel), and

Code: Select all

return $dph //(typo?)
into my user defined function. Am I right? Your //comments kind of confused me.

Again, t //(typo?)

into my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Absconfused me.

Again, thanks for taking the time.

Absble to figure out where I'm supposed to place things. My understanding of your code right now is that I am supposed to put

Code: Select all

$dbh=dbconnect();
into my index.php (the control panel), and

[php:1:c for the reply!

Because I'm new at this I have not really been able to figure out where I'm supposed to place things. My understanding of your code right now is that I am supposed to put

Code: Select all

$dbh=dbconnect();
into my index.php (the control panel), and

Code: Select all

return $dph //(typo?)
into my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Abs understanding of your code right now is that I am supposed to put

Code: Select all

$dbh=dbconnect();
into my index.php (the control panel), and

Code: Select all

return $dph //(typo?)
into my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Abs$dbh=dbconnect();

into my index.php (the control panel), and

Code: Select all

return $dph //(typo?)
into my user defined function. Am I right? Your //comments kind of confused me.

Again, thanks for taking the time.

Abs
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

I'm sorry about that, I see now it's quite confusing.
You call your function and place its return value to a variable

Code: Select all

# Include file
include('./include.php');
# Run the function from the include file
$dph=dbconnect();
Function returns a value

Code: Select all

function dbconnect() {
# Set the Connection Variables
// do stuff
# Open the database

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then return a value
return $dph;
}
ase

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then return a value
return $dph;
}/include.php');
# Run the function from the include file
$dph=dbconnect();
Function returns a value

Code: Select all

function dbconnect() {
# Set the Connection Variables
// do stuff
# Open the database

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then retubles
// do stuff
# Open the database

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then return a value
return $dph;
}
);
//do stuff and checks
//and then return a value
return $dph;
}ce its return value to a variable

Code: Select all

# Include file
include('./include.php');
# Run the function from the include file
$dph=dbconnect();
Function returns a value

Code: Select all

function dbconnect() {
# Setat, I see now it's quite confusing.
You call your function and place its return value to a variable

Code: Select all

# Include file
include('./include.php');
# Run the function from the include file
$dph=dbconnect();
Function returns a value

Code: Select all

function dbconnect() {
# Set the Connection Variables
// do stuff
# Open the database

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then return a value
return $dph;
}
# Include file
include('./include.php');
# Run the function from the include file
$dph=dbconnect();
Function returns a value

Code: Select all

function dbconnect() {
# Set the Connection Variables
// do stuff
# Open the database

@ $dbh = new mysqli($host, $username, $password, $database);
//do stuff and checks
//and then return a value
return $dph;
}
Abs
Forum Newbie
Posts: 7
Joined: Sat Jul 09, 2005 11:59 am
Location: Toronto, Canada

THANK YOU!

Post by Abs »

:D Thank you very much for all of your help wwwapu. You saved me from a huge headache! I really appreicate the quick replies. :)

Abs
Post Reply