[Snippet] PHP Code to Submit data into Database

Although we use the framework to submit data into the database, sometimes we need a pure PHP code to insert data into the database. Honestly, sometimes we forget the command to insert data into the database, because the framework has been easier for us.

And this morning, I get a case where I have to enter the data into the database without using the framework. I usually use cakephp.

Here are a few lines of code that is easy to learn.

?php
function mysql_insert($table, $inserts) {
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);
        
    return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (''.implode('','', $values).'')');
}
?>

For example:

<?php

mysql_insert('cars', array(
    'make' => 'Aston Martin',
    'model' => 'DB9',
    'year' => '2009',
));
?>

very easy right?

Snippet Code : How to Force Download Image from Unsplash.com with PHP

force-download-unsplash-image

Who does not know unsplash? Unsplash is a website that provides free large size images, you can use for any purpose. Their promise is: give 1 HD image, high quality for free every day. The images you can use for a blog post, templates, brochures or in print.

Well, I need a way to transfer the picture into my server. Here’s the code I used. Perhaps, you will need it.

<?php 
$file = 'https://ununsplash.imgix.net/photo-1422479516648-9b1f0b6e8da8?q=75&fm=jpg&s=c5f2b3df2a4c71532b3b354b8766503c';
download($file);

function download($url) {
    set_time_limit(0);
    $ch = curl_init();
	$rename="newname_".date('y_m_d_G_i_s');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $r = curl_exec($ch);
    curl_close($ch);
    header('Expires: 0'); // no cache
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
    header('Cache-Control: private', false);
    //header('Content-Type: application/force-download');
    //header('Content-Disposition: attachment; filename="' . basename($url) . '"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . strlen($r)); // provide file size
    header('Connection: close');
    //echo $r;
	
	$fp = fopen("$rename.jpg",'w');
	fwrite($fp, $r); 
	fclose($fp);
}
?>

I am was tested it and working 100%.

If this snippet is help you, please share in your social network.

Want to get new wordpress theme? just visit our brand new wordpress theme directory

Essential Tips to Integrate Google Spreadsheets in PHP

php with spreadsheet google

Like most of the people, you must be using Google spreadsheets a lot. They are a bit handy to balance the checkbook, set up a monthly, weekly or regular budget, and importantly estimating as well as controlling the project schedules. If you have already switched over from your desktop spreadsheet application to the one and only Google spreadsheets, then you must know the advantages of using it. Google spreadsheet is nothing but a cloud-based service that supports almost all spreadsheet features and they are all user-friendly at the same time. People, these days, are switching from the traditional spreadsheet using to Google spreadsheet for two key advantages. They are:

  • They can access their spreadsheet data on the move.

  • They feel that sharing, collaborating and editing the data are significantly easier than using a desktop application.

php with spreadsheet google

Now the question is what makes the Google spreadsheets particularly user-friendly and interesting? From a developer’s angle of vision, is it possible a Data API helps developers build new applications around the user space spreadsheets data easily and quickly? One can easily access this API by way of XML capable development toolkit. Albeit, Google provides excellent client libraries for both the Java and PHP technologies.

Breaking the Barrier of Language

If you want to play nicely with data in various formats, if you are a developer then you must know that PHP is a bit difficult to beat. The language does make a breeze to deal with the SQL result sets and XML files but also comes with solid extensions to deal with diverse formats, like Vorbis audio files, ZIP archives as well as EXIF headers. Therefore, PHP can read and write with Google spreadsheets, though with a little assistance from PEAR. In this article, we will introduce top tips that help you make surprisingly easy and quick to hook up your PHP scripts up to a Google spreadsheet as well as extract the data contained therein. Here we will tell you some tips that work with Google spreadsheets in PHP, and you will come to know how to dynamically build a new. Things to know before you work on it.

  • Understand Google spreadsheets feed properly. It is important because spreadsheets feed contains a number of spreadsheets that are widely available for users.

  • You should know how to retrieve the spreadsheets. Google spreadsheets feed are generally encoded with the HTML. You should know HTML, if you are a PHP developer and well versed with PHP, then you must know how to do it.

  • You should know how to retrieve the worksheet rows. You must question why this tip? You should know there are two ways Google spreadsheets data API offers. One the list feed and another is cell feed.

  • Understand how to retrieve the worksheet cells. This thing is very, very important. As a developer, you should know it; otherwise, you will face trouble working with Google spreadsheets in PHP.

  • You should know how to retrieve worksheet data as arrays. Some shortcut methods would be there if you know PHP properly and finding the shortcut way would be your handy tip to make it possible.

  • One of the most important tips is to know how to filter the worksheet data. However, you can easily and quickly filter the content of a wide range of list feed that matching the specific criteria. Here three important tips for you; find the spreadsheet and worksheet ID and the filter criteria to make it quickly.

Now you have come to know the basics to retrieve the data from the Google spreadsheets Data API and use the techniques to work with PHP. Just you need to know few practical examples that help you put all in one context to do it properly. 

What do You need to Know Before You Do It?

When you are about to work with Google spreadsheets in PHP, there are some important things that you need to know, better to say these things will help you a lot to do the work effectively and efficiently. Make sure that you have a web server that has PHP installed. Create a Google account and sing in to access the spreadsheet and apply PHP the way you need with Google spreadsheet.

Author Bio:-

Sunny Chawla is a Marketing Manager at AIS Technolabs- webdesign and Development Company. Helping global businesses with unique and engaging tools for their business.

He would love to share thoughts on php app development , web design etc..

Hypertext Preprocessor And Its Advantages

php logo

One of the popular programming languages, PHP is rapidly mounting to be one of the most ideal web browser programming languages because to its efficiency, accessibility and user control. PHP permits a user to illustrate explicit functions within the code in array to considerably control the method a web browser organizes or displays information. A user is capable to merge HTML and PHP within the same file to attain the yearned effect. In this article, we will converse about how PHP toils as well as why it is fancied by the populace who use it.

What is PHP?

php logo

Hypertext Preprocessor which is commonly known as PHP, is a programming language that permits the consumer to have more power over the HTML that formulates up a website page. PHP permits for additional functions that HTML does, such as login functions, DIV tables as well as graphical displays. PHP was initially recognized as a Personal Homepage, which illustrates the idea of the language. PHP toils along with HTML in the same document which permits the users to systematize as well as display information by a web browser which is facile compared to the other programming languages. PHP is not intricate and one can become pertinent at. Furthermore allocates the users to design web-page which looks or toils according to their determination.

Boons of PHP:

The enlisted below are the benefits and advantages of utilizing PHP:

Comprehendible:

PHP is preferred among users because it is easy to read and understand. Many programming languages are complex and intimidating to new users while PHP is organized, clean, and fluent. PHP documents do not have to necessarily be in any order which allows for users to quickly add new functions whenever they want without having to make sure that the new code is in the correct place. This is excellent for users who have long scripts for many of their pages, especially for style sheets and reference documents.

Modified:

PHP is also uncomplicated to edit or amend. A user is capable to swiftly scan a PHP document for the amendments or for looking out the codes. There are numerous other programming languages which necessitate that you have to adjust numerous functions within numerous documents in array to do the same procedure that PHP can do effectually. PHP documents can moreover be effortlessly integrated into an assortment of individual PHP commands or several other PHP documents. This allocates the users to obtain ample benefits of their computer experience or programming skills as they can write their individual PHP extensions and scripts devoid of handling a great sum of data.

Additional Control;

benefit of php

PHP proffers more power over the web browsers than various other programming languages do. There are countless programming languages call for large scripts to perform effortless tasks whereas PHP can carry out the same task just with a fewer number of codes. PHP permits consumers to design web pages according to their requirements and needs. The prolific feature of this is that it toils effectually along with several other languages resourcefully. The users are more able to muse over the web-design instead of the programming language. This is the plus point of PHP.

Superior and Enhanced Performance:

PHP toils auspiciously as it is much better in performance if compared with several other programming languages. PHP is prompt, competent, and as well as toils miraculously with countless software as well as it can be integrated to any server pertinently. on a  PHP document, a user is capable to tot up a few lines of code and then save it as well as they are able see their website, revolutionize into a more prevailing moreover more structured-out edition itself. PHP is also speedily mounting in its competence furthermore proffers additional features which facilitate to maintain an apt software.

Free of Charge:

Another rationale that PHP is ideal among consumers is that it is exclusively free. Although many other programming languages necessitate that the user acquires pricey and exorbitant programs as well as has to pay for support files, PHP is unbolt to anyone and everywhere and at any time. A learner in PHP doesn’t have to fret about finding assistance for their significance in web designs and programming, as there is an intact online society enthusiastic to assist others in PHP management and execution. PHP is also abetted by countless corporations, who throw in to for accomplishment on a day by day.

However the pros of PHP show and give us the notion that PHP is the finest, culminating as well as prolific platform for the programming language as well as for designing a competent website. Such program facilitates the user to articulate their conceptions, notions and initiatives via web designing etc. As PHP is the first-rate software as it lend a hand to the user who is a beginner as it functions efficiently. A designer especially web-designer ought to choose this programming language software to attain accomplishment and triumph resourcefully.

Author Bio: I am Victoria Lucy, I have been toiling in this Web Design Company as a content writer. I yearn to moil for this company, a peerless and best SEO services to venture. It is a first-rate services yielder plus unimpeachable for its consumers. A very contented and appreciative milieu is provided to its workers. Meticulous and adroit company with you must work or get services with. It’s being noteworthy to be a part of it, as it the prevailing company where clients and employees are brandish copacetic way. This company is primo, competent and optimum company in terms of providing services to its clienteles. Acquiring services from this company will be benevolent and will be a sanction for you definitely.

Crucial Pillars of Modern PHP Development

Important-pillars-of-modern-PHP-development

Among the number of prominent programming languages out there, PHP enjoys being one of the most prominent and most-loved. On the easy end of the learning spectrum, it just requires you embedding the code within HTML, hence it comes around as a must-learn language for aspiring web developers all over the globe.
It stands for Hypertext Preprocessor and mainly it’s used in conjunction with dynamic data-heavy websites and app development offering a lot of power and excels when compared to a number of monster sites such as WordPress and Facebook. The cool attribute of this programming language is that it’s an open-source language offering myriad of free pre-built modules that can be grabbed and modified so you attain desired results.

What makes it widely chosen language for development is it supports a number of other languages like Perl, C and many others. Besides it comes with a few unique features of its own, such as flexibility, free from any licensing restrictions, free of cost easy, capable and many more.
Development with PHP ensures that your project gets the support from all major web servers including Microsoft IIS, Apache, Netscape, personal web server, iPlanet server and many others. Moreover, PHP supports all major databases like MySQL, IBM DB2, dBase, FrontBase, ODBC, PostgreSQL, SQLite, etc.
“The aforementioned insight reveals that PHP developmentis a very useful, beneficial, effective and feature-rich programming alternative and it is commonly used for developing active sites. With advancement in the modern day technology we noticed many new add-ons to this language as well.”

Meanwhile, here we discuss the key pillars of modern PHP development.

1. Code

This is one of the major aspects of your application. Let’s begin with it. Here we tell you what it’s all about.
Management
Different versions of PHP are responsible for coding. Developers are advised to take the shelter of Git due to its wide spread and availability across the board as we have no clue about its truly superior alternatives.
Style
Following the specified coding standards will get its share because steady coding is easy to comprehend by other team members; therefore, adding a new member becomes easy. No matter what the size of the team is (it can be even a single developer): code maintenance can easily accept the majority of a projects time and perfectly formatted and document code is the chief factor in decreasing the efforts.
Open Source
If would be extremely amazing if you open source your application code. It gives you an opportunity to enhance the quality, cost-free marketing for yourself or your company and providing support to the community as one unit. One more time, you are advised to take help from Git. It could be difficult to locate developers who can spend some extra time.
This style also influences the level of acceptance and inclination to participate. The existing standards also allow newcomers to hit the right spot making without altering their intentions.

2. Tests

What has been the black sheep of the PHP family is the automated testing. Nevertheless, there is a huge change in the time taken due to this and the development time will be double. A well-tested application gets a lot of benefits including:

  1. It becomes extremely convenient to refractor the tested software
  2. What reinforces modular design is Unit Testing
  3. Tests offer an example code and documentation

 

3. The State of Being Dependant

Dependencies should definitely be dealt with Composer. Since the code is well-coupled with a particular package/library, the dependency declaration should be in the version control as well. What should not be a part of version control are the actual package/library files, since their revisions are commanded by the declaration already, therefore, it remains under version control and it would be unnecessary to do both.
Modularization
What changes your mindset towards modularization of your own code is being a user of libraries/packages itself. This leads to less code repetition across projects and thus reduces efforts, increasing quality in the long run.

4. Runtime Data

All file based data is included in Runtime data, which is produced at runtime by user communication. This is best handled using a local network linked file system. Our recommendation is cloud storage as they instinctively provide solution to various scalability issues and this reduces future migration issues, natively balance load by splitting execution and delivery.

5. Configuration

If this practice is done intensely, it can be a great hindrance when shifting your application. Moreover, it can be a security risk.
Split Configuration from Code
It’s best alternative to use the environment and it’s actually about environment variables, however it seems that local configuration files again comes around as a valid choice – as long as their deployment are well-specified.
What is the best solution is to examine whether the configuration is well split up from the code or not. It is possible to open source your code without exposing any credentials right now? If you say yes, then it’s good.

6. Resources

These are the services brought into use by the application, such as databases, queues, caches, storages mentioned above, mail delivery etc.
Keep It Abstracted
What you need to abstract is the access to resources and the degree of this process should rely on possibility and feasibility. The place of resources has to be substituted by configuration as mentioned above.

7. Assets

Asset data like JavaScript, CSS, images etc., are extremely difficult to choose from. To cut it short, we advise is to keep them under version control. The collection of JavaScript and CSS or making improved examples of images requires an amazingly huge and distinct tool set which has a large dependency set of its own. This leads to increased complexity of the deployment infrastructure without the need. As well as there is responsibility issue – like, at most times assets are handled by the frontend developers of the team. Same as specialized developers, they have their tools that do wonders to them. This forces asset compilation in the release cycle and this way there is a need to limit themselves to the tools available here.
Conclusion
It is essential to know more about the coding patterns, testing, deployment strategies and application design when we discuss the modern application development and the role of PHP in the same. Owing to a range of tools, better services and coding standards, it is now easy to comprehend it as they help and support on a large scale.

Author Biography
Arun Goyal, founder and CEO at Octal Info Solution Technology, carries profound experience in IT industry and based on that he creates informative and engaging piece of content. He expresses his outlook in his recent creation, hire PHP developer, which displays a great insight of the subject valuable for many of his followers. Explore him through his ideas on a number of domains and as a part-time author of this blog. Connect with him on Twitter, Facebook and LinkedIn.

To be a True Web Developer, What Programming Language Should I Learn?

how to be web developer

Some people may be confused when they have to learn how to create a website. He does not know where to start learning programming language to create a website. So, to make the Website needed some programming language, at least using PHP. For UI, you can use HTML

HTML is widely believed to be not a programming language, but in HTML there is conditional syntax. And it is also believed that conditional Sinta is one of the conditions it recognizes as a programming language. But we do not need to discuss it. The obvious website requires HTML to display information with the correct format.

Then the required knowledge in the field of PHP. As is known that PHP is a programming language that is processed on the server side. Then the results of the processing will be sent to the web browser via http server. That’s the flow of a working website.

Then I get a lot of questions, what programming languages ​​should I learn in order to create a website. Actually, for now create a website is not always done by the programmer, because many services and software that allows someone to create a website. One of them is WordPress that is widely used by bloggers and people who do not know the language of web programming.

But if you want to learn how to build a website, then the programming language you have to master is

1. HTML

Html serves to display the information correctly and this is a mutually agreed standard. Html is easy to learn, the syntax is not complicated. What is needed is imagination, that is when we write HTML tags, our minds have imagined what kind of results. It seems difficult, but if you are familiar with the HTML language it will be formed by itself.

Estimated time to study html about 3 days only, with intensity of study time of day for 8 hours.

2. PHP

Actually if you just want to create a simple website without the need to connect to the database, then you do not need to learn PHP. PHP allows the website to run dynamically. Content that is on the website Can be updated dynamically by using PHP

PHP allows a website to connect with the database. Usually the database used is my SQL. In PHP there is a function that can connect to the database. So if you really want to master web programming then learn PHP is the first step before mastering other programming languages ​​like Python.

3. JavaScript

JavaScript is actually needed to make the website look more attractive and can improve the user experience. But the latest javascript technology can be used to communicate with the server. Although we know that, javascript is a client-side programming on the Browser.

For JavaScript, you can learn it after mastering html and PHP. I think this javascript is advanced.

That is the basic programming language that must be mastered to become a web developer

What The Difference NodeJS and PHP? Read This Post

nodejs logo

What is the difference between NodeJS and PHP ? I see on the internet there are people who ask about it. For me, this question is ridiculous but maybe there are people who have not understood what different nodes JS and PHP. I’ve used node.js and I’ve also used PHP to design applications.

So, I want to explain the fundamental differences of the NodeJS and PHP . Both are indeed programming languages ​​but the NodeJS runs on the client side while PHP runs on the server side. Node JS uses javascript language to run the program while PHP is a programming language processed on the server side and then provide output of the value that is sent to the client through Browser.

NodeJS

The superiority of the NodeJS is the same as desktop programming where there is no time limit for a function to run, the term is non blocking i /o. Here’s what I love about node.js, we can create executable applications without time constraints using javascript without having to use a web browser.

We know for sure that javascript is a machine for processing Java scripts attached to Browser. While node.js is a javascript programming language that can be executed independently. I usually use node.js to create apps like bot, submitter, Scraper and others. Why I use node.js because the programming language is very easy to understand like JavaScript.

Node JS can also run on all operating systems including Linux and Windows. I also run some node.js scripts on the vps server. On the Linux operating system especially Ubuntu has included node.js program that you can directly use without having to install.

PHP

This is my favorite programming language when creating web based applications. No other programming language I use other than PHP so far, it’s specifically for creating websites. I have never used asp.net issued by Microsoft to create web applications

When I was studying on campus, there was a course that talked about asp.net, but I do not really like the programming language of this microsof. I do not know maybe because I do not like microsof. I prefer to use open source program.

Until this article was written, PHP has been developed up to version 7 and now much more stable. Almost all modern applications including WordPress already support PHP version 7.

So that’s the difference between Node JS and php. Hopefully this article can help brighten all my friends when learning programming language

Complete Guide : How to Setup Web Server on Linux and Install WordPress

Eye Drawings

Using Linux and the web server sometimes have to read a lot of tutorials and step-by-step. I can not memorize one by one. So, I wanted to make this post useful for the newbie who wants to create a server with linux.

What is needed is

  1. Ubuntu 14.04 or above
  2. Internet connection

This tutorial will discuss

  1. How to install PHP, MySQLand Apache2 and seting it up
  2. How to change webroot location to your home directory  or where you want
  3. Install phpmyadmin
  4. Install wordpress

Ok, lets begin. Open your terminal and get into step one

Install Apache2

Use this command and enter

sudo apt-get update
sudo apt-get install apache2

Install MySQL

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

You will get prompt to setting up database. Fill password and enter. Its simple

Install PHP

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

After this step your server is ready to battle. Your webroot directory in /var/www/html/

Try to open localhost in your browser. Ok, let go to step two.

Change Webroot Directory

Maybe some of you want to change the webroot directory so as not to touch your linux system. The most convenient way is to move the webroot to your home directory, eg /home/dono/www

We will try to make this easier. There are 2 files that you must change.

  1. file apache2.conf dengan alamat /etc/apache2/apache2.conf
  2. file ooo-default.conf dengan alamat /etc/apache2/sites-available/000-default.conf

Edit Apache2.conf

sudo gedit /etc/apache2/apache2.conf

Search this code lines

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

And change as look like this

<Directory /home/dono/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Save and done

Edit ooo-default.conf

sudo gedit /etc/apache2/sites-available/000-default.conf

And search this line

DocumentRoot /var/www/ and change to DocumentRoot /home/dono/www

Then save.

Fix permission

sudo chmod -R 777 www-data:www-data /home/dono/www

Dont forget to restart your server with this command

sudo service apache2 restart

Install PHPMyAdmin

Ok, just use this command

sudo apt-get install phpmyadmin apache2-utils

You will get prompt to setting your PHPMYadmin configuration. Its simple. Dont forget to include PHPMyAdmin config file to apache config file, in order you can access phpmyadmin with simple URL like this

http://localhost/phpmyadmin

sudo gedit /etc/apache2/apache2.conf

then add this code in apache2.conf file (in below)

Include /etc/phpmyadmin/apache.conf

Then save. Done

Install WordPress

Install wordpress is very simple step. We use wget to downlaod wordpress file

cd /home/dono/www
wget http://wordpress.org/latest.zip

unzip latest.zip

Then install wordpress by http://localhost/wordpress.

Bonus : Fix WordPress Ask FTP account

Sometimes when you want to install a plugin or theme, wordpress ask FTP username and password. Actually, this is not necessary. All you have to do is with a few lines of code to fix this.

sudo chown -hR www-data:www-data /home/dono/www/wordpress

Thanks to narga.net for provide this tricks

That is a short tutorial for setting up a linux server and installing wordpress. I wrote this tutorial to remind myself and help friends all