Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

How to connect to a sql database with php

Patchy TN asked on January 18, 2017

Hi,I’m new to all of this and don’t know much about sql.
I read the guide but still confuse about this
Step 2: Setup Data Compressor on the server
First of all, you need to add the following dependency to your project, flexmonster-compressor.php is located in the Download Package:


Below is the connection and query sample for MySQL database:

mysql_connect($server, $username, $password);
$result = mysql_query("SELECT * FROM customer");

The following line of code will start streaming compressed $result:

header('Content-Type: text/plain');

What I understand is just put flexmonster-compressor.php to the server,right?
and then where should I put the sql query code? in flexmonster-compressor.php or in another file?

2 answers

Ian Sadovy Ian Sadovy Flexmonster January 18, 2017

Hello Patchy,
Thank you for the question.
Yes, you should put flexmonster-compressor.php on the server.
Also, you should create a separate PHP file with all code from Step 2.
SQL query is defined in the following line of code:

$result = mysql_query("SELECT * FROM customer");

You can find fully working PHP sample in the downloaded package for SQL (/server/php/).
Does it work for you?

Patchy TN January 19, 2017

it works,thank you!

Please login or Register to Submit Answer