Thursday, July 23, 2020

How to install composer in MAC OS

In this guide, i'm installing Composer on a machine running Mac OSX with MAMP.
  1. Open a terminal and navigate to your user directory, ie cd /User/<USER_NAME>/
  2. Run this command shown below to download Composer. This will create a Phar (PHP Archive) file calledcomposer.phar:
    curl -sS https://getcomposer.org/installer | php
    
  3. Now we move composer.phar fileto a directory
    sudo mv composer.phar /usr/local/bin/
  4. We want to run Composer with having to be root al the time, so we need to change the permissions:
    sudo chmod 755 /usr/local/bin/composer.phar
    

  5. Next, we need to let Bash know where to execute Composer: 
    nano ~/.bash_profile
    
    Add this line below to bash_profile and save
     
    alias composer="php /usr/local/bin/composer.phar"
    
    and then run this command:
     
    source ~/.bash_profile

  6. Finally, run: 
    composer -v

Tuesday, November 4, 2014

www.dynamic-coders.com

Hi All,
From now onwards all my recent posts and blogs can be found on http://www.dynamic-coders.com .
Including the blogs listed on this blog.
visit: www.dynamic-coders.com

Thursday, January 9, 2014

How to execute update query by applying join on two different tables in different databases on same server

update <dbname of 1st table>.<table name of 1st table> A INNER JOIN <dbname of 2nd table>.<table name of 2nd table> RA ON A.<field name of table 1>=RA.<field name of table 2> SET A.<field name of table 1 to be updated>=RA.<field name of table 2 to set value in table 1>


Replace data in < > with your appropriate values.

Thats It.
 

Tuesday, January 7, 2014

How to replace degree(°) with " & deg;" using php


$myvalue=" +1°C to +10°C";
$r=preg_replace("/\xB0/", '&deg;', $myvalue);

$myvalue will contain value that you want to replace.

Wednesday, December 18, 2013

how to export mysql table as csv using php?


Use the below code snippet as it is,just make sure to include your config file which has connection with the database.
make a file named generate.php .
<?php
include("config.php"); //config file containing connection to your database,you can name it whatever you want.
// Fetch Record from Database

$output            = "";
$table             = "mytable"; // Enter Your Table Name
$sql             = mysql_query("select * from $table");
$columns_total     = mysql_num_fields($sql);

// Get The Field Name

for ($i = 0; $i < $columns_total; $i++) {
    $heading    =    mysql_field_name($sql, $i);
    $output        .= '"'.$heading.'",';
}
$output .="\n";

// Get Records from the table

while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}

// Download the file

$filename =  "myFile.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

echo $output;
exit;
   
?>

If you want to generate csv file on click of any button or link.Just give path of this file in the link.Like:
<a href="generate.php">generate csv</a>

Tuesday, December 17, 2013

What is sql injection?How to prevent it.

sql injection means injecting a query in database the always retun true.So it allow to login with false credentials.For example: use
' or '1'='1
 
in place of username and password and it will logged you in.
If sql injection is not prevented.
 
It can be prevented by implementing a check during login.
 
$user=mysql_real_escape_string($_REQUEST['user']);
$pass=mysql_real_escape_string($_REQUEST['pass']); 

Thats all.Clean n simple.

How to made/create a zip file using php.

class FlxZipArchive extends ZipArchive
{

/**
* Add a Dir with Files and Subdirs to the archive
*
* @param string $location Real Location
* @param string $name Name in Archive
* */
public function addDir($location, $name)
{
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
}

/**
* Add Files & Dirs to archive.
*
* @param string $location Real Location
* @param string $name Name in Archive
* */
private function addDirDo($location, $name)
{
$name .= '/';
$location .= '/';

// Read all Files in Dir
$dir = opendir($location);
while ($file = readdir($dir)) {
if ($file == '.' || $file == '..')
continue;

// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$do = (filetype($location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, $name . $file);
}
}

}

function create_zip($archive_folder, $archive_name){

    @unlink($archive_name);

    $za = new FlxZipArchive;

    $res = $za->open($archive_name, ZipArchive::CREATE);
    
    if($res === TRUE) {
    $za->addDir($archive_folder, basename($archive_folder));
    $za->close();
    }
    else
    echo 'Could not create a zip archive';
}//end of function


//now call the function where ever you want
$archive_folder="";//enter folder name here
$archive_name="";//enter name of zip file you want to create here
create_zip($archive_folder,$archive_name);

Feel free to comment ,if it works for you.Thanks!!