Latest From My Blog

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
The following information will teach you how to generate a unique order number using PHP. Below is the PHP code snippet generating unique order number.

I have used below code in my recent eCommerce project :-)
Have a fun :-)
DOWNLOAD CODE


Generate Order Number Using PHP

PHP curl with proxy:

The following information will teach you how to use curl function behind a proxy. Below is the simple PHP code snippet requesting given URL using curl and HTTP proxy server.

$loginpassw = 'login:password';  //your proxy login and password here
$proxy_ip = '127.0.0.1'; //proxy IP here
$proxy_port = 8080; //proxy port from your proxy list
$url = 'http://example.com'; //URL to get

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); // no headers in the output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // output to variable
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);

PHP curl with proxy

How to set the http_proxy Variable in Windows7/Windows8

The following information will teach you how to allow Windows7/Windows8 system to use a proxy server to download some external packages/plugins using command line.
Example: I have used this option to update composer and install packages in my recent laravel project.

Steps to set the http and https proxy variable

1.     Open the command prompt.
2.     Paste following http_proxy  and https_proxy command in cmd
set HTTP_PROXY=http://{{USERNAME}}:{{PASSWORD}}@{{PROXY_URL}}:{{PROT_NUMBER}} 
set HTTPS_PROXY=http://{{USERNAME}}:{{PASSWORD}}@{{PROXY_URL}}:{{PROT_NUMBER}}
{{USERNAME}}  -  Proxy Username.
{{PASSWORD}} – Proxy Password.
{{PROXY_URL}} – Proxy Url.
{{PORT_NUMBER}} – Proxy Port Number.
Now your system ready to download resource (packages/plugins) from the internet using command line.

How to set the http_proxy Variable in Windows7/Windows8

How to Import/Export a MySQL Database
MySQL command is used to export large database in easiest and fastest way. This example shows you how to export/import a database. It is good to export your data often as a backup.
Export a MySQL Database
      1.     If you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. If you are using WAMP server then this will be usually located in:
C:\wamp\bin\mysql\mysql5.6.17\bin (*note the version of mysql might be different) and then SHIFT+RIGHT CLICK and click on the Open Command Window Here from specified path.


2.     After the first step execute the below command in command prompt.
                   mysqldump -u {DB-USER-NAME} -h {MySQL-SERVER-HOST-NAME} -p {DB-NAME} > {NAME-OF-THE-FILE.sql path}
      3.     You will be promoted for a password, type the password for the respective username and press Enter. Replace the username, password and database_name with your MySQL username, password and database name.

4.     The file test.sql now holds a backup of your database and is ready for download in your computer.
5.     To export a single table from your database you can use the following command:
                 mysqldump -p --user={DB-USER-NAME} {DB-NAME} {TABLE_NAME} > tableName.sql
6.     Again you would need to replace the username, database and tablename with the correct information. Once it is done the table specified would be saved to your computer as tableName.sql.
      Import a MySQL Database
      1.     Locate.Sql file in following specified directory C:\wamp\bin\mysql\mysql5.6.17\bin.

2.     If you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. If you are using WAMP server then this will be usually located in:
C:\wamp\bin\mysql\mysql5.6.17\bin (*note the version of mysql might be different)     and then SHIFT+RIGHT CLICK and click on the Open Command Window Here from specified path. Refer above screen shot.
3.     Next run the command in command prompt:
     mysql -u {DB-USER-NAME} -h {MySQL-SERVER-HOST-NAME} -p {DB-NAME} < {db.file.sql path}
      4.     To import a single table into an existing database you would use the following command
                mysql -p --user={DB-USER-NAME} {DB-NAME} {TABLE_NAME} > tableName.sql

How to Import/Export a MySQL Database using MySql command line

+