0

Hello DaniWeb,

I've finally gotten around to swapping from MySQL to MySQL(i), mainly due to it's security advantages with Prepared Statements.

In the past I've been adding include ('/Some/Directory/File.php); to the top of each page, so that I can store my functions in a secure directory and so that I only need to edit it once (such as if I change the password for the database).

When I attempted to do this in MySQL(i), I cannot get it to work. For example,

function Index_Visits()
    {
        $Connect = mysqli_connect('localhost', '***', '***', '***');

        $Query = "SELECT Index_Visits FROM SiteStatistics WHERE ID = 1";
        $Result = mysqli_query($Connect, $Query);

        $Row = mysqli_fetch_array($Result, MYSQLI_ASSOC);

        $CurVisits = $Row['Index_Visits'];

        echo $CurVisits;
    }

I use the above to display the total number of page visits to the Index Page, it is only part of it but it gives you an example.
When I go to call this, such as Index_Visits(); it shall work fine if it is in the same file, but if I store the function in a seperate .php file and include it and then try to execute it, it shall not work... no errors, no display, just a blank browser.

Edited by Octet

4
Contributors
9
Replies
11
Views
4 Years
Discussion Span
Last Post by Octet
0

@AHarrisGsy

but if I store the function in a seperate .php file and include it and then try to execute it, it shall not work... no errors, no display, just a blank browser.

Change this

$Query = "SELECT Index_Visits FROM SiteStatistics WHERE ID = 1";

to this:

$Query = "SELECT Index_Visits FROM SiteStatistics WHERE id=1";

Edited by LastMitch: grammer

0

Nope, nothing.

Thanks for the suggestion though, LastMitch.

As I say, it works fine when it is in a single file but when I try and include it from a seperate file it breaks.

Edited by Octet

0

@AHarrisGsy

As I say, it works fine when it is in a single file but when I try and include it from a seperate file it breaks.

I realized what you did and you missed something:

Read this closely and you will realize the issue:

http://php.net/manual/en/mysqli-result.fetch-array.php

I will give you a hint:

it's an ->

Here is how it looks:

$row = $result->fetch_array(MYSQLI_ASSOC);

Edited by LastMitch: grammer

0

I realized what you did and you missed something:

Read this closely and you will realize the issue:

But if I am doing it Procedural Style?

I have also tried it OOP style, with no luck.

1

In my experience, a blank screen after making a change in PHP usually indicates some fatal error is happening in the PHP. You can try turning display_errors on and setting error_reporting to E_ALL.

Also be sure to check the path in your include statement to make sure it is correct.

Votes + Comments
Nice Answer!
0

I copied your situation and tested the code on my own wamp server and it worked fine. I moved the include file above the document root and it still worked okay. This wamp server is so sensitive it throws an error if I look at the screen funny.

1

In my experience, a blank screen after making a change in PHP usually indicates some fatal error is happening in the PHP. You can try turning display_errors on and setting error_reporting to E_ALL.

Also be sure to check the path in your include statement to make sure it is correct.

Hey, thanks for the tip about ini_set. It showed up an error with the include path, although the path was correct it didn't like it unless I had:

$_SERVER['DOCUMENT_ROOT'] in it..

Strange, $_SERVER['DOCUMENT_ROOT'].'/PHP/Services/Index_Visits.php is exactly the same as /PHP/Services/Index_Visits.php in this instance as index.php is in the Document Root and PHP is equally in the Document Root.

Edited by Octet

0

@AHarrisGsy

Hey, thanks for the tip about ini_set. It showed up an error with the include path, although the path was correct it didn't like it unless I had:

$_SERVER['DOCUMENT_ROOT'] in it..

Good to know!

Edited by LastMitch: grammer

0

Thanks for the help,

LastMitch
dcdruck
adam.adamski.96155

Hopefully now I can re-write my existing sites using the more secure MySQLi and Prepared Statements!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.