How to Become a Chatbot Ninja in 7 Days

Module 5: Lesson 5.1. Database integration with PHP/MySQL

Lesson 5.1. Database integration with PHP/MySQL

When you know how to implement this MySQL course into your business, a lot of features become a breeze. Possibilities are endless when using your own MySQL database. It's not for nothing almost all dynamic websites are based on this platform. eCommerce, WordPress and almost all other CMS programs use MySQL and now you can do the same with ManyChat.

For this lesson I recorded the entire video where I set the database table up, as well as show you how fast and easy this can be. A few things aren't in the video (i noticed after recording it), but I will explain in detail what you need to do right here.

First, the video. Let's have a look.

What's missing in the video is:

1. the part where I should have told you how to set up your database credentials;
2. where you can edit the text that is sent back to ManyChat;
3. what all the extra fields in the table we created are.

1. Your database credentials

This data is something you should have from your hosting service, you can fill it in in these fields:

////-------------------------------------  CREATE CONNECTION
$servername           = "localhost";
$username             = "";
$password             = "";
$dbname               = "";
$dbtable              = "";

2. Change the text in the Dynamic Response

For this demo we just send back the query result (insert or update), plus the fruit we like best. You can however send back any text you desire to ManyChat. You can find that in the next section of the script:

////------------------------------------- SETUP JSON
$myArray = array("version" => "v2");
$content = array();

$textArray     = array("type" => "text", "text" => $response . "\n\r\n\rYour favorite fruit is " . $favorite_fruit);
$content['messages'][] = $textArray;

$myArray['content']    = $content;

3. The extra fields in the table

The extra fields in the table have no purpose at this point, but we created those as placeholders for your project. You can change them to anything, just like we changed custfield_01 into favorite_fruit

 

Plus, as in all other scripts throughout the course, please do yourself a favor and restrict access to your scripts by setting the page_id check.

////------------------------------------- CREDENTIALS / PAGE CHECK
$allowed_pages = array("123","456"); // set to your page id(s) to restrict outside access
if (!in_array($page_id, $allowed_pages))exit;
Downloads: You need at least a Silver Membership to be able to download this content