Using PHP and MySql in VS Code - php

I would like to run PHP along with MYSql in VS Code as I would run using 'xammp'. I came across some extensions to use like IIS-Express and vscode-database but don't know how to configure and link them together.And which PHP would be suitable i.e. Thread safe or non Thread Safe.
PS: I am completely new to learn PHP and VS Code and want to use VS Code for every language I learn :)

IIS Express is an extension that will basically run your project folder as a website. It's an extremely handy tool that I couldn't live without. Usage is simple, and noted below. I should also point out that IIS Express is only available for Windows and will not work on Linux or OSX.
File > Open Folder
Select the folder with your PHP and HTML within
Install the IIS Extension from the extension menu. (Or with the command palette using "ext install iis-express")
Open the command palette (CTRL + SHIFT + P)
Type "IIS Express: Run Website"
This starts the web server and will open a browser and connect to your website for testing.
To stop the server, simply type the command a second time.
More information can be found here.
After looking around, it seems vscode-database does not host an actual database, but rather, gives you a way to test your queries in the editor. The information page for vscode-database doesn't make that very clear, though. So for MySQL functionality, you may want to look at running MySQL in a "portable mode". Instructions for this can be found here.
After getting that setup, you would just connect to it in php like any other MySQL database.

Related

How to prototype with PHP and HTML5 forms when I cannot view the result?

I recently started PHP (I am a beginner) and I wanted to create a form with HTML to add numbers together. However, when I send queries to PHP it shows my source code (because it is not a server - file is run locally). I was wondering would it be possible to preview my PHP's code result on a website of some sort or even better on my computer? Do you know any services or ways to accomplish this, preferably free of charge?
To run php files online, go to Write Code Online.
As long as you can install programs on your computer, you should install a web server to run php files locally. To run any basic app, especially if it uses forms, you will use multiple php files and the testing will be too complex to run online. If you are using windows, install wamp. For mac, try mamp.
you seriously require some help :-)
First, PHP is a server side scripting language, so it requires server (like Apache, which you can install using the wamp or xampp installers) Try to search google on how to install them on local computer.
Second, their are some online PHP editors, like http://www.compileonline.com/execute_php_online.php or writecodeonline .com and many others. It may not replace the server but helps to write the PHP code and execute it for the sake of practising.
Also, it is better if you read some tutorials about PHP. One tutorial I can point you to is the http://www.w3schools.com/php/php_form_complete.asp which is related to question.

How Can I make portable xampp project

Let I have developed a dictionary application in mysql using php in xampp. That is i can access it using localhost from my browser. But i do not want it to be online. I want to release an offline version of it. So that I can distribute the project using cd or pendrive and user just take it and run it. That is I want to make it portable in offline.
How can I do that. That is should I install xampp in all the cd and import my database ? Or is there any smart solution?
By it's very nature, XAMPP is portable. You can just extract it and run it. When you run it it will run Apache, mySQL and you can access it by http://localhost or by a different address according to your host file configuration if it has been changed from the default.
So put it on a laptop or onto a pen drive and you can run your code and database from it.
Here's the description of XAMPP:
XAMPP is an integrated server package of Apache, mySQL, PHP and Perl (the AMPP in XAMPP) that all run from a removable drive. Everything is pre-configured and ready to go just by unzipping or installing it.
Why not to search first? )
There is similar question: https://stackoverflow.com/a/12272455/2792335
I think you should first migrate database from MySQL to something like SQLite to avoid need of db server installation.
Then use something like http://www.nusphere.com/products/phpdock.htm or one of applications referenced in the above mentioned answer.
PHP and mysql is not a good platform for such task. PHP to operate need running sever(i.e apache) with support for right version of php. an mySQL is commercial product, you can use it for free, but if you want to include it with your product as you described you need commercial license. I would suggest to rewrite product to another platform. In example you can use JavaScript and HTML5 storage instead for data. or pick different database.

how to start php?

I am asp.net developer , i want to learn php
what are the software need to run compile php file ?
how to install this software any path that should be set ?
what kind of database it needs to store data and retrieve date ?
see me as beginner and then give the idea / information ..........
thanxx
You just need the PHP interpreter and if you want to do web stuff a webserver.
You can get the interpreter from http://www.php.net - if you are using windows you really want to get a binary version and not compile it on your own - and the Apache webserver.
As a database PHP developers usually use MySQL (but it can also connect to most other databases).
The easiest way for your to get started is getting a package like XAMPP which will contain all you need without requiring you to configure everything manually.
For actually learning PHP, please get a recent book/tutorial. Old stuff is usually telling people to do horribly things every sane developer will hate you for (cluttering your global namespace with variables settable by the user for example).
You could have a look at the official PHP docs which also contains a "getting started" guide.
Since you are an ASP.NET developer I assume that you are familiar with IIS and that you're probably using IIS 7.5. If so then the easiest way to familiarize yourself with PHP is to use Microsoft Web Platform Installer and install PHP directly to IIS. You don't have to set any paths after that, just create a site on IIS and start putting PHP files there. Keep in mind that Web Platform Installer automatically enables WinCache extension and your changes might not be there when you hit the refresh button. Just locate the php.ini and comment out the relevant line.
Straight from the horses mouth. Getting Started. You will need a php interpreter, if you have access to a webhost that has php installed you're half way there, if you have a linux partition you're half way there, otherwise check out XAMPP.
Software: XAMPP will get you up and running
Tutorial: w3schools
If you are familiar with IIS and want to use it as your web server you can download PHP for IIS here and use some of the learning material there to get started.
If you did not want to use IIS and wanted to use Apache instead then I agree with the others XAMPP will get you a dev environment up and running quickly.

How to get started with sql and php?

I was wondering how to link a SQL database on my PHP code.
I am using a database on my local server that I set up and I have already created a database, I tried writing a PHP script with ++notepad, but when I clicked on the script, it opened the browser and displayed a blank page. What am I doing wrong? I created my databases using phpMyAdmin.
You need to be running a web server locally which supports PHP (like Apache). It it the web server which does the PHP processing. At the same time you will have to run a MySQL (or any other) database engine too, so your PHP code can connect and query it. (I'm assuming you've already installed PHP.)
I would recommend you install XAMPP which includes Apache, PHP, MySQL and a bunch of other stuff. It one of "Apache friends". Once you install XAMPP you would have a folder htdocs in the xampp folder. Create a folder for you project myproject and place your PHP script script.php in there. Now if MySQL and Apache are running following should behave as you expect.
http://127.0.0.1/myproject/script.php
For the tutorial, to begin with you can use W3Schools. Brief and to the point. They have both a PHP tutorial and a SQL tutorial.
This is a very good book to start with:
PHP and MySQL
Web Development
Luke Welling and Laura Thomson
You have to play with php/sql code practically. Only reading cant help!
go for w3shools as mentioned above :)
start with simple code and then go to the complexity. all the best.. :)
There are multiple ways on how to do that.
One of the most modern ways to do that, is to use PDO to connect to the DB with PHP.
To run PHP on your PC(which i assume is your workstation), you need the supporting software for it, for php to run you need the PHP software installed, and likewise if you want to run the server software you need apache, however you can go for a single install package which will install almost everything for you to run your php script, download and install the wamp.
to install wamp which stands for (windows, apache, mysql, PHP) if you are running windows, and lamp for linux or mamp for mac, all of which are free softwares, you can download wamp from the following link. http://www.wampserver.com/en/download.php that is the first step which you need to do.
step 2: once wamp is installed the default directory of installation is C:/wamp (i reccomend do not change the location of the installation), you need to start the wamp server by just opening or double clicking the software which you just installed.
step3: navigate to the default directory where you should be storing your PHP files and that is C:/wamp/www note that you should be keeping all your PHP files here apart from this location if you store it anywhere else it wont simply run at all, and that it should and must have the .php extension.
step4: create or save the php files in this location(c:/wamp/www) i for example will assume you have created a file test.php in the www folder. now to access this file open your web browser and type http://localhost/test.php there you go, you will have the access to your PHP file (Note: PHP files cannot be run by simply double clicking the file, you have to follow this procedure in order to run the PHP files)
step5: open the test.php in any of your text editor like notepad, or i recommend use an IDE (Netbeans is free and worth a try), and write your code in the following format.
<?php
your PHP code should go here.
?>
when i started writing the code i started by following a nice tutorial which i found in zend.com, it has one of the best examples, and moreover the tutorial is meant for the beginners. hope this helps you..
http://devzone.zend.com/tag/PHP101

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

Categories