MySQL: “Too many connections” in opencart 2.0.3.1 - opencart2.x

I recently installed opencart 2.0.3.1. Since I have installed opencart I get the below error
Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 7
Notice: Error: Could not make a database link (1040) Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 10
Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 58
Below is the opencart code from file mysqli.php
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->link = new \mysqli($hostname, $username, $password, $database, $port);
if ($this->link->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
exit();
}
$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");
}
Below is the screen shot of phpmyadmin advisor. which states opencart is using too many connection. This seems to be a bug

Related

Why is my data forbidden when trying to display it on a web page?

I am in a group project with three other members where we are trying to connect to an API, store the data from that API into a shared database, and display it on a web page by accessing our code file through a server. For our project, we are connecting to four different music streaming API's, mine being Spotify. Individually, we wrote our own code in Python to connect to each of our API's and extract data to be stored in our own database. In my code, I searched the name of a particular musician, and when running the code, I connected to Spotify's API and received an output of that musician's top 20 tracks. Those 20 tracks were stored in a table in my own database in MySQL Workbench, with the columns 'tracks' and 'items'.
Now, each of my members and I have our data tables for our individual API's stored into one shared database in MySQLHosting.net. Currently, my group is struggling to print and display the data from each of our tables onto a web page. I have written a PHP file attempting to display my table for Spotify's data, and I saved the file on my server and ran chmod 755, but when I search for my PHP file in the browser, I am left with a
403 Error ("Forbidden: You don't have permission to access this
resource").
Can anyone help me figure out if it is an error in my code, or if I need to run a different chmod command? Below is the code I used to display my data.
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "sql5.freemysqlhosting.net";
$username = "[removed for question]";
$password = "[removed for question]";
$dbname = "[removed for question]";
$port = "[removed for question]";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
$mysqli = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$mysqli)
{
echo 'Connection failed<br>';
echo 'Error number: ' . mysqli_connect_errno() . '<br>';
echo 'Error message: ' . mysqli_connect_error() . '<br>';
die();
}
echo 'Successfully connected!<br>';
$sql = "SELECT tracks, items FROM spotify";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "tracks: " . $row["tracks"]. "<br>" . "items: " . $row["items"]. "<br>";
}
}
else
{
echo "0 results";
}
$conn->close();
?>
</body>
</html>

PHP Stripe customers->search not finding accurate results

I'm having difficulty with STRIPE customer->search returning incorrect results sometimes.
If I search for a customer, and if it does not exist then add it, then repeat - I can find it adds the customer a second/third/fourth/etc times - for a while. Meanwhile on the stripe dashboard, I can see the customers appearing [multiple times].
If I waited a few minutes between initial refreshes - it seems ok.
Perhaps there's a cache, or a lag or something between adding a customer and the search finding it but this is not very helpful. Am I wrong - or is there something I'm not doing?
The relevant PHP code is here:
$stripe = new \Stripe\StripeClient($stripe_secretkey);
echo "<LI>Searching for $customerNm...</LI>";
$json = $stripe->customers->search(['query' => 'name:\'' . $customerNm . '\'']);
foreach ($json->data as $key) {
echo "<LI>Found id:[" . $key->id . "]";
if (strcmp($key->name, $customerNm) == 0) {
$customerId = $key->id;
$email = $key->email;
break;
}
}
echo "<hr>";
if (strcmp($customerId, "") == 0) {
echo "<LI>Result to search is <PRE style='margin-left:20px'>$json</PRE>";
$email = str_replace(" ", "", str_replace(" ", "", "abc#$customerNm.com"));
$json = $stripe->customers->create(
[
'email' => $email,
'name' => $customerNm,
]);
$customerId = $json->id;
echo "<UL>Created New STRIPE customer id: [$customerId]</UL>\n";
}
}
This code can be found running on a sandbox here** where if you were to run the page multiple times - it will keep creating customers [for a while].
(Note, this page will create a cookie "posterUID" which is used as the customer name; once it's created then it stays until expiry or manual deletion).
** The full source to this can be seen here
This is expected behavior per Stripe's Search documentation:
Don’t use search for read-after-write flows (for example, searching immediately after a charge is made) because the data won’t be immediately available to search. Under normal operating conditions, data is searchable in under 1 minute. Propagation of new or updated data could be more delayed during an outage.

Fatal error with Stripe Checkout: Class 'Stripe' not found

I'm trying to implement Stripe Checkout into my website. I am using Composer, everything seems to go right, but when I add my private key into init.php line 17:
Stripe::setApiKey($stripe['private']);
PHP shows me the following error:
Fatal error: Class 'Stripe' not found in/Applications/MAMP/htdocs/stripe_payment/app/init.php on line 17
Here is the full file:
<?php
session_start();
//composer auto load
require_once 'vendor/autoload.php';
$_SESSION['user_id'] = 3;
$stripe = [
'publishable' => '..... my test key.....',
'private' => '..... my test key.....'
];
//when added brakes the code
Stripe::setApiKey($stripe['private']);
$db = new PDO('mysql:host=localhost;dbname=stripe_custom;','root','root');
$userQuery = $db->prepare("
SELECT id, username, email, premium
FROM users
WHERE id = :user_id
");
$userQuery->execute(['user_id' => $_SESSION['user_id']]);
$user = $userQuery->fetchObject();
?>
I presume that this is something small, but I'm a beginner and I can't figure it out. What am I doing wrong?
The latest releases of Stripe's PHP bindings (2.*) are now using Namespaces. This means that most of the API calls have now changed and for example:
Stripe::setApiKey("sk_test_XXX");
Stripe_Customer::create();
would become:
\Stripe\Stripe::setApiKey("sk_test_XXX");
\Stripe\Customer::create();
Otherwise, if you don't want to have to update your code you need to make sure that you download the legacy version (1.18.0).

Wordpress Plugin: Facebook comments box position

I have a problem with the "new" Facebook plugin for Wordpress. I would like to re-position it on my post page. I've read somewhere else (or maybe here) that you could use the comment box from developers.facebook.com but I want to use the original Facebook plugin. So here goes:
I've found (in the plugin folder) where Facebook have put the code to install comments box in my theme. It looks like this:
public static function the_content_comments_box( $content ) {
global $post;
if ( ! isset( $post ) )
return;
$options = get_option( 'facebook_comments' );
if ( ! is_array( $options ) || empty( $options ) )
return $content;
// closed posts can have comments from their previous open state
// display noscript version of these comments
$content .= "\n" . self::comments_markup( 'noscript' ) . "\n";
// no option via JS SDK to display comments yet not accept new comments
// only display JS SDK version of comments box display if we would like more comments
if ( comments_open( $post->ID ) ) {
$url = apply_filters( 'facebook_rel_canonical', get_permalink() );
if ( $url ) // false could happen. let JS SDK handle compatibility mode
$options['href'] = $url;
$content .= self::js_sdk_markup( $options );
}
return $content;
}
}
How do put the Facebook comments box in the bottom of my post page?
You can look at a random post page here: My temporary site What I'm ultimately trying to do is to have Facebook Comments box after Relaterede indlæg (related posts).
Is this at all possible?
I don't use the FB plugins for Wordpress because they seem bloated to me. However, here's a simple one-line code that I use to add a facebook comments box. You can place it anywhere in any template.
<div class="fb-comments" data-href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>"></div>
PLEASE NOTE: this method requires that you have the Facebook SDK installed on the site. Also, it won't work as a widget unless you have enabled the ability to execute PHP in your widgets (requires a plug-in).

Update SharePoint Default Alternate Access Mapping Programmatically

I'm enabling HTTPS on my IIS server where I have SharePoint Services 3.0 installed and I'd like to programatically update the default alternate access mappings for a single web application and my central administration instance (both on the same machine). Here's the code I have so far (Powershell), it adds a mapping for HTTPS but I get and error when trying to remove the original one.
Here's my code:
[void][system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$SPWebServiceCollection = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection ([Microsoft.SharePoint.Administration.SPFarm]::Local)
foreach ($SPWebService in $SPWebServiceCollection) {
foreach ($webApplication in $SPWebService.WebApplications) {
Write-Host ('Updating {0}' -f $webApplication.Name)
foreach ($alternateUrl in $webApplication.AlternateUrls) {
$incomingUrl = [System.URI] $alternateUrl.IncomingUrl
$newURL = 'https://{0}{1}' -f $incomingUrl.Authority, $incomingUrl.PathAndQuery
$newAltURL = New-Object Microsoft.SharePoint.Administration.SPAlternateUrl ($newURL, $alternateUrl.UrlZone)
$webApplication.AlternateUrls.Add($newAltURL)
$webApplication.AlternateUrls.Update($true)
$webApplication.AlternateUrls.Remove($alternateUrl) #Throws Exception
$webApplication.AlternateUrls.Update($true)
}
}
}
Here is the error I get when I try to remove the original:
Exception calling "Remove" with "1" argument(s): "An object in the SharePoint administrative framework, "SPAlternateUrlCollection Name=SharePoint - 1000 Parent=SPFarm Name=SharePoint_Config_8ddd3701-a332-4e79-98e4-fa11c1b6c17c", could not be deleted because other objects depend on it. Update all of these dependants to point to null or different objects and retry this operation. The dependant objects are as follows:
SPWebApplication Name=SharePoint - 1000 Parent=SPWebService
However, i'm not sure how to do what the exception suggests.
Ah... it looks like you are trying to remove the URL the Webservice is using...
It turns out there's another method for the exiting default entry that I overlooked:
$webApplication.AlternateUrls.SetResponseUrl($newAltURL)
[void][system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$SPWebServiceCollection = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection ([Microsoft.SharePoint.Administration.SPFarm]::Local)
foreach ($SPWebService in $SPWebServiceCollection) {
foreach ($webApplication in $SPWebService.WebApplications) {
Write-Host ('Updating {0}' -f $webApplication.Name)
foreach ($alternateUrl in $webApplication.AlternateUrls) {
$incomingUrl = [System.URI] $alternateUrl.IncomingUrl
$newURL = 'https://{0}{1}' -f $incomingUrl.Authority, $incomingUrl.PathAndQuery
$newAltURL = New-Object Microsoft.SharePoint.Administration.SPAlternateUrl ($newURL, $alternateUrl.UrlZone)
$webApplication.AlternateUrls.SetResponseUrl($newAltURL)
$webApplication.AlternateUrls.Update($true)
}
}
}

Resources