Archive for January, 2008
Display textarea content with line breaks in html page
Let us see how javascript, php, and ruby display the content of textarea with line breaks
Javascript:
document.getElemnetById(‘textareacontent’).value.replace(/\n/g,’<br>’);
PHP:
preg_replace(“/\n/”,”<br>”,$_REQUEST['t1']);
Ruby:
(teaxtareacontent).gsub(/\n/,”<br>”)
PHP Singleton Object
The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.
Here is an example, that demonstrates this singleton pattern: (more…)
Take the dump of database from the console
To take dump of whole database:
$ mysqldump -u <username> -p <databasename> > <filename>.sql
To take dump of the (only)structure of the database
$ mysqldump -u <username> -p <databasename> -d > <filename>.sql
To take dump of the (only)data of the database
$ mysqldump -u <username> -p <databasename> -t > <filename>.sql
To take dump of the database with complete insert statement
$ mysqldump -u <username> -p <databasename> -c > <filename>.sql
How to create database using mysql commands
To create database from command prompt. Login to mysql as root user.
To login into mysql prompt in linux machine.
Type the following command in the console
$ mysql -u <username> -p<password>
After entering the mysql prompt follow these steps to create a database
and load the database with sql file.
A CREATE DATABASE statement to create a database.
> create database <databasename>;
A GRANT statement to grant privileges to database.
> grant all on <databasename>.* to <username>@localhost identified by ‘<password>’;
A FLUSH PRIVILEGES statement to tell the server to reload the grant.
> flush privileges;
A USE statement to tell the server to use the given database for further operations.
> use <databasename>;
A SOURCE statement to tell server to load the given sql file in the database.
> source <filename.sql>
Recent Comments