Help with a smart home project using PHP and MYSQL

Hi there,

I would need some help for a smart home project.
I want to build the system using PHP and MySql to administrate the digital and analogue pins for an Arduino Mega.
The ideea is that all pins should be initialised on arduino with the initial state Input.
There should be a loop for gathering the pinmode and pin state from a php page(I don't know how to make that loop) and another loop to update the informations from the sensors to Mysql.

Arduino should work in this way.
Initialising all the pins in input mode.
Gather informations from a php page for the pins, like D0= Input, D1= Output(Low), D2= Output(High) so in this way we will control the arduino pins remote.
Post the informations from all the sensor's in a mysql database for logging and to make scenarios.
Now we will have a page where we can setup different scenarios based on [if D0=1 then D2=High] so all the setup will be made remotely without touching the arduino code.

Thanks for your help!

I don't know how to make that loop

You should start with making the Arduino act as client, to GET the results of executing that script. Do nothing more than print the results.

Once you know what the input will look like, you can working on saving and parsing the input.

Post the informations from all the sensor's in a mysql database for logging and to make scenarios.

You have this wrong. POST the information to a PHP script. What the PHP script does with the information is completely irrelevant. One of the things it could do is store the data in a database.

Now we will have a page where we can setup different scenarios based on [if D0=1 then D2=High] so all the setup will be made remotely without touching the arduino code.

If you are thinking that the Arduino can get data from a browser, you are wrong. You could have one PHP page that presents a web page, with certain settings. That page could contain a form with one or more submit buttons. Those buttons could trigger another script that would store the data somewhere.

You could have a third script that the Arduino made a GET request for, that would fetch the stored data and return it to the Arduino-as-client.