https://github.com/gggordon/php-sql-replacer
Replace values in SQL inserts even if serialized using PHP
https://github.com/gggordon/php-sql-replacer
copy migration php replace-text sql
Last synced: 4 months ago
JSON representation
Replace values in SQL inserts even if serialized using PHP
- Host: GitHub
- URL: https://github.com/gggordon/php-sql-replacer
- Owner: gggordon
- License: mit
- Created: 2020-10-16T23:59:18.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-19T02:51:19.000Z (over 5 years ago)
- Last Synced: 2024-05-13T11:21:40.123Z (almost 2 years ago)
- Topics: copy, migration, php, replace-text, sql
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/gggordon/php-sql-replacer)
[](https://scrutinizer-ci.com/g/gggordon/php-sql-replacer/)
[](https://codecov.io/gh/gggordon/php-sql-replacer)
[](https://packagist.org/packages/gggordon/php-sql-replacer)
[](https://packagist.org/packages/gggordon/php-sql-replacer)
[](//packagist.org/packages/gggordon/php-sql-replacer)
# PHP SQL Replacer
A utility to replace strings/values in `SQL` files especially with **serialized** `php` values. Useful for database migrations/clones.
# Installation
```
composer require gggordon/php-sql-replacer
```
# Usage
## Command Line Usage
```
./bin/php-sql-replacer --input-file-path="./original.sql" --output-file-path="./updated.sql" --match="Original Text" --replace="New Text"
Required Options:
--input-file-path : Path of input file
--output-file-path : Path of output file
--match : Exact string to look for
--replace : String to replace match with
```
## Using Code
If you already have the contents stored as a string, you may follow the example below to replace the contents.
```php
replaceValue(
$contents,
"trading",
"butter"
);
echo $updatedContents;
```
to get the following output:
```sql
insert into test (column1, column2) values ('I like butter','Another Value')
```
**OR**
If you are extracting the contents from a file:
```php
replaceValueFromFile("/path/to/original_file.sql", "trading", "butter", "/path/to/output_file.sql");
echo $updatedContents;
```
to get the following output:
```sql
insert into test (column1, column2) values ('I like butter','Another Value')
```
and a new file created at `/path/to/output_file.sql`.
# Tests
Testing done using [`phpunit`](https://phpunit.de/)
```
phpunit
```
# Documentation
Documentation Generated using [`phpdox`](http://phpdox.de/)
```
phpdox
```
# License
MIT License
# Maintained by
[ gggordon](https://github.com/gggordon)