Importing data from non-wordpress mysql database


Hits: 3272  

You have to create an import php file to get the Questions/Answers from a non-wordpress database and bring them into posts in wordpress.

Question Table

<?php

/// non-wordpress database connection string here

require('./wp-load.php');

$results = mysql_query("SELECT * FROM questions");

while ($row = mysql_fetch_assoc($results)) 
{

    $post_information = array(
	'post_title' => wp_strip_all_tags( $row['question'] ),
	'post_content' => $row['answer'],
	'post_category' =>  array(6,7), // Cat Ids
	'post_date' => date('Y-m-d H:i:s', strtotime( $row['timestamp'] )),
	'post_type' => "post",
	'post_excerpt' => "",
	'post_author' => "admin",
	'post_status' => "publish"
	);
	
	$post_id = wp_insert_post( $post_information );		
	
	$filename = "http://www.domain.com/images/post-image.png";   ////  Post Thumbnail Image
	$wp_filetype = wp_check_filetype(basename($filename), null );
	
	$attachment = array(
	  'post_mime_type' => $wp_filetype['type'],
	  'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
	  'post_content' => '',
	  'post_status' => 'inherit'
	);
	
	$attach_id = wp_insert_attachment( $attachment, $filename, $new_post );
	
	//update_post_meta($post_id,'_thumbnail_id',$attach_id);	
	
	add_post_meta($post_id, '_thumbnail_id', $attach_id, true);

}

?>

Recover MySQL root Password


Hits: 3109  

1. Stop the MySQL server.

# /etc/init.d/mysql stop

2. Start the MySQL server process with the –skip-grant-tables option so that it will not prompt for password.

# mysqld_safe –skip-grant-tables &

3. Connect to mysql server as the root.

# mysql -u root

mysql password
mysql password

Welcome to the MySQL monitor….
………..
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>

4. Setup new mysql root account password i.e. reset mysql password.

mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit

5. Exit and restart the MySQL server.

# /etc/init.d/mysql stop

6. Start MySQL server.

# /etc/init.d/mysql start
# mysql -u root -p

 

 

Replace phpMyAdmin by Adminer


Hits: 5111  

Adminer (formerly phpMinAdmin) is a full-featured database management tool written in PHP. It consist of a single file ready to deploy to the target server. Adminer is available for MySQL, PostgreSQL, SQLite, MS SQL and Oracle.

phpMyAdmin-Adminer
phpMyAdmin-Adminer

phpMyAdmin is one of the most famous tools for managing the MySQL database. However, Adminer have important differences with phpMyAdmin are:

* User experience
* Supported MySQL features
* Performance
* Security

adminer-screenshot
adminer-screenshot

Replace phpMyAdmin by Adminer and you will get better user interface, better support for MySQL features, higher performance and more security.

Features

* Connect to a database server with username and password
* Select an existing database or create a new one
* List fields, indexes, foreign keys and triggers of table
* Change name, engine, collation, auto_increment and comment of table
* Alter name, type, collation, comment and default values of columns
* Add and drop tables and columns
* Create, alter, drop and search by indexes including fulltext
* Create, alter, drop and link lists by foreign keys
* Create, alter, drop and select from views
* Create, alter, drop and call stored procedures and functions
* Create, alter and drop triggers
* List data in tables with search, aggregate, sort and limit results
* Insert new records, update and delete the existing ones
* Supports all data types, blobs through file transfer
* Execute any SQL command from a text field or a file
* Export table structure, data, views, routines, databases to SQL or CSV
* Alter export for projecting changes to production database
* Print database schema connected by foreign keys
* Show processes and kill them
* Display users and rights and change them
* Display variables with links to documentation
* Manage events and table partitions (MySQL 5.1)
* Schemas, sequences, user types (PostgreSQL)
* Extensive customization options

Requirements

* Works with MySQL, PostgreSQL, SQLite, MS SQL, Oracle – Improve your driver
* Supports both PHP 4.3.3+ and PHP 5 with enabled sessions
* Available in Arabic, Catalan, Chinese, Czech, Dutch, English, Estonian, French, German, Hungarian, Italian, Japanese, Lithuanian, Persian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish, Tamil, Turkish, Ukrainian, … (28) – Create a new translation
* Free for commercial and non-commercial use (Apache License or GPL 2)

Upgrade PHP & MySQL on Plesk 10


Hits: 3130  

1. Stop Running Apache & MySQL Server
# /etc/init.d/mysqld stop
# /etc/init.d/httpd stop

2. Set up the atomic channel
# wget -q -O – http://www.atomicorp.com/installers/atomic | sh

3. Upgrade to PHP 5.3.x on plesk 10
# yum upgrade

Now I can install “uploadprogress” extension easily

pecl/uploadprogress requires PHP (version >= 5.2.0), installed version is 5.1.3
No valid packages found
install failed

# pecl install uploadprogress

Then add in /etc/php.ini

extension=uploadprogress.so

CentOS Latest RPM for PHP MySQL


Hits: 6691  

[root@svnlabs ~]# yum install php php-soap php-xmlrpc php-imap php-mcrypt php-mhash php-mbstring php-mysql php-xml php-gd php-cli php-common php-api
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: centos.mirrors.tds.net
* extras: mirror.sanctuaryhost.com
* updates: mirror.fdcservers.net
Setting up Install Process
Package matching php-5.1.6-32.el5.i386 already installed. Checking for update.
Package matching php-mcrypt-5.1.6-15.el5.centos.1.i386 already installed. Checking for update.
Package matching php-mysql-5.1.6-32.el5.i386 already installed. Checking for update.
Package matching php-cli-5.1.6-32.el5.i386 already installed. Checking for update.
Package matching php-common-5.1.6-32.el5.i386 already installed. Checking for update.
Resolving Dependencies
–> Running transaction check
—> Package php-gd.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-gd
—> Package php-imap.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-imap
–> Processing Dependency: libc-client.so.1 for package: php-imap
—> Package php-mbstring.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-mbstring
—> Package php-mhash.i386 0:5.1.6-15.el5.centos.1 set to be updated
–> Processing Dependency: php-api = 20041225 for package: php-mhash
—> Package php-soap.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-soap
—> Package php-xml.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-xml
—> Package php-xmlrpc.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-xmlrpc
—> Package php53-common.i386 0:5.3.3-5.el5 set to be updated
–> Running transaction check
—> Package libc-client.i386 0:2004g-2.2.1 set to be updated
—> Package php-gd.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-gd
—> Package php-imap.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-imap
—> Package php-mbstring.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-mbstring
—> Package php-mhash.i386 0:5.1.6-15.el5.centos.1 set to be updated
–> Processing Dependency: php-api = 20041225 for package: php-mhash
—> Package php-soap.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-soap
—> Package php-xml.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-xml
—> Package php-xmlrpc.i386 0:5.1.6-32.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-32.el5 for package: php-xmlrpc
–> Processing Conflict: php53-common conflicts php-common
–> Finished Dependency Resolution
php53-common-5.3.3-5.el5.i386 from base has depsolving problems
–> php53-common conflicts with php-common
php-soap-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-soap-5.1.6-32.el5.i386 (base)
php-xml-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-xml-5.1.6-32.el5.i386 (base)
php-mbstring-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-mbstring-5.1.6-32.el5.i386 (base)
php-gd-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-gd-5.1.6-32.el5.i386 (base)
php-imap-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-imap-5.1.6-32.el5.i386 (base)
php-mhash-5.1.6-15.el5.centos.1.i386 from extras has depsolving problems
–> Missing Dependency: php-api = 20041225 is needed by package php-mhash-5.1.6-15.el5.centos.1.i386 (extras)
php-xmlrpc-5.1.6-32.el5.i386 from base has depsolving problems
–> Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-xmlrpc-5.1.6-32.el5.i386 (base)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-xml-5.1.6-32.el5.i386 (base)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-gd-5.1.6-32.el5.i386 (base)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-xmlrpc-5.1.6-32.el5.i386 (base)
Error: php53-common conflicts with php-common
Error: Missing Dependency: php-api = 20041225 is needed by package php-mhash-5.1.6-15.el5.centos.1.i386 (extras)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-mbstring-5.1.6-32.el5.i386 (base)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-imap-5.1.6-32.el5.i386 (base)
Error: Missing Dependency: php-common = 5.1.6-32.el5 is needed by package php-soap-5.1.6-32.el5.i386 (base)
You could try using –skip-broken to work around the problem
You could try running: package-cleanup –problems
package-cleanup –dupes
rpm -Va –nofiles –nodigest
The program package-cleanup is found in the yum-utils package.

…….

# rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
# yum –enablerepo=webtatic install php php-mysql

OR

# yum –enablerepo=webtatic update php php-mysql
# php -v

PHP 5.3.11 (cli) (built: Apr 27 2012 22:00:56)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

# service httpd restart

Now try with PHP 5.4.1 (Current stable)

Installing Apache, MySQL, PHP in CentOS 5.5 on Rackspace Cloud


Hits: 30957  

Most of cloud users prefer Rackspace Cloud for its better service and cost effectiveness…
All commands are performed as root to install Apache, MySQL, PHP in CentOS 5.5 Server on Rackspace Cloud.

Install Apache

# sudo yum install httpd mod_ssl

Configure ServerName
# sudo /etc/init.d/httpd start

Remove Error
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using xx.xx.xxx.xx for ServerName

Modify
# sudo vi /etc/httpd/conf/httpd.conf

Add server name after #ServerName www.example.com:80

ServerName svnlabs

# sudo /etc/init.d/httpd reload

By default port 80 is blocked on server, enable in iptables…
# iptables -I RH-Firewall-1-INPUT -p tcp –dport 80 -j ACCEPT

Chkconfig to start automatically if the Cloud Server is rebooted.

# sudo /sbin/chkconfig httpd on

Install MySQL

# yum install mysql-server
# /etc/init.d/mysqld start

Install PHP

Edit Repo file
# sudo vi /etc/yum.repos.d/CentOS-Base.repo

add at last

[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

now run
# yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-mbstring

Install PhpMyAdmin

# cd /var/www/html
# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.6/phpMyAdmin-3.3.6-english.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1283745912&use_mirror=voxel

# tar zxvf phpMyAdmin-3.3.6-english.tar.gz
# mv phpMyAdmin-3.3.6-english phpmyadmin
# cd phpmyadmin
# cp config.sample.inc.php config.inc.php

Edit config.inc.php for random string $cfg[‘blowfish_secret’] = ‘RandomStringHere’;

Restart server
# service httpd restart

Comparison between Amazon Cloud & Rackspace Cloud … Coming Soon 😉

PHP ORM – Create select box with mysql set or enum


Hits: 6014  

PHP have rich set of functions to solve real time problems in programming and web development.. thanks to Rasmus Lerdorf

eval — Evaluate a string as PHP code

A SET datatype can hold any number of strings from a predefined list of strings. The ENUM datatype restricts to a single member of the set of predefined strings, the SET datatype allows to store any of the values together, from none to all of them.

CREATE TABLE svnlabs_set (
name SET(‘lamp’,’web’,’linux’,’joomla’)
);

CREATE TABLE svnlabs_enum (
name ENUM(‘lamp’,’web’,’linux’,’joomla’)
);

If we want to fill the html select box with these two tables…

SHOW COLUMNS FROM svnlabs_set;
> set(‘lamp’,’web’,’linux’,’joomla’)

SHOW COLUMNS FROM svnlabs_enum;
> enum(‘lamp’,’web’,’linux’,’joomla’)

now based on column type set list of string values from mysql to php array…

<?php

…….

// if column type is set
$arr = “\$set=”.str_replace(“set”, “array(“, $column[‘Type’]));
eval($arr);

// if column type is enum
$arr = “\$set=”.str_replace(“enum”, “array(“, $column[‘Type’]));
eval($arr);

…………..

?>

Use $set PHP array to fill select box….

Upload Large Database Table to Server


Hits: 1946  

Hello Friends,

Sometime we want to upload large database table to server but phpMyAdmin have limit to upload SQL large *.sql files..

When we create database table “svnlabs” from mysql admin server make 3 files “svnlabs.frm”, “svnlabs.MYD” and “svnlabs.MYI”

These files are located at “/var/lib/mysql/svnlabs”.. we can check this location by phpinfo.php

svnlabs-table
svnlabs-table

We can upload all these 3 files to server using ftp or rsync.

Here source location may be either Windows or Linux and destination may be both.

We can upload zip of all 3 files “svnlabs.frm”, “svnlabs.MYD” and “svnlabs.MYI” for the table “svnlabs” and after upload to server; we can unzip to mysql folder “/var/lib/mysql/svnlabs”.

As files successfully uploaded to online server we can check new table “svnlabs” from phpMyAdmin.

Keep up good work…. 🙂

Installing XAMPP in Linux


Hits: 7168  

What is XAMPP ?

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. LAMPP (XAMPP for Linux) is very easy to install and to use – just download, extract and start.

Download XAMPP

http://sourceforge.net/projects/xampp/files/XAMPP Linux/

Installing XAMPP in Linux

Download XAMPP Latest version from the following link
http://sourceforge.net/projects/xampp/files/XAMPP Linux

Currently latest XAMPP version is 1.7.3a

$wget http://downloads.sourceforge.net/project/xampp/XAMPP%20Linux/1.7.3a/xampp-linux-1.7.3a.tar.gz?use_mirror=nchc

Now you should be having xampp-linux-1.7.3a.tar.gz in your downloaded location

Go to a Linux shell and login as root:
Perform these commands as root user

$ su -p
Extract the downloaded archive file to /opt

#tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt

XAMPP is now installed below the /opt/lampp directory.

Start XAMPP Server

To start XAMPP simply call this command:

#/opt/lampp/lampp start

Starting XAMPP for 1.7.3a…
XAMPP: Starting Apache with SSL (and PHP5)…
XAMPP: Starting MySQL…
XAMPP: Starting ProFTPD…
XAMPP for Linux started.

Test Your XAMPP Installation

OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:

http://localhost

Starting LAMPP automatically on startup
Starting LAMPP automatically on startup

XAMPP Security Configuration

As mentioned before, XAMPP is not meant for production use but only for developers in a development environment. The way XAMPP is configured is to be open as possible and allowing the developer anything he/she wants. For development environments this is great but in a production environment it could be fatal.

Here a list of missing security in XAMPP:

The MySQL administrator (root) has no password.
The MySQL daemon is accessible via network.
ProFTPD uses the password “lampp” for user “nobody”.
PhpMyAdmin is accessible via network.
Examples are accessible via network.
MySQL and Apache running under the same user (nobody).
To fix most of the security weaknesses simply call the following command:

#/opt/lampp/lampp security

It starts a small security check and makes your XAMPP installation more secure.
Start And Stop Server Services

start
Starts XAMPP.

stop
Stops XAMPP.

restart
Stops and starts XAMPP.

startapache
Starts only the Apache.

startssl
Starts the Apache SSL support. This command activates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay activated.

startmysql
Starts only the MySQL database.

startftp
Starts the ProFTPD server. Via FTP you can upload files for your web server (user “nobody”, password “lampp”). This command activates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay activated.

stopapache
Stops the Apache.

stopssl
Stops the Apache SSL support. This command deactivates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay deactivated.

stopmysql
Stops the MySQL database.

stopftp
Stops the ProFTPD server. This command deactivates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay deactivated.

security
Starts a small security check programm.

For example: To start Apache with SSL support simply type in the following command (as root):

#/opt/lampp/lampp startssl

You can also access your Apache server via SSL under https://localhost.

Important Configuration Files And Directories

/opt/lampp/bin/ – The XAMPP commands home. /opt/lampp/bin/mysql calls for example the MySQL monitor.
/opt/lampp/htdocs/ – The Apache DocumentRoot directory.
/opt/lampp/etc/httpd.conf – The Apache configuration file.
/opt/lampp/etc/my.cnf – The MySQL configuration file.
/opt/lampp/etc/php.ini – The PHP configuration file.
/opt/lampp/etc/proftpd.conf – The ProFTPD configuration file. (since 0.9.5)
/opt/lampp/phpmyadmin/config.inc.php – The phpMyAdmin configuration file.

Stopping XAMPP

To stop XAMPP simply call this command:

#/opt/lampp/lampp stop

You should now see:

Stopping XAMPP 1.7.3a…
XAMPP: Stopping Apache…
XAMPP: Stopping MySQL…
XAMPP: Stopping ProFTPD…
XAMPP stopped.

And XAMPP for Linux is stopped.

Starting LAMPP automatically on startup

For starting LAMPP automatically on startup, add the following line to you /etc/rc.local file

# /opt/lampp/lampp start

where /opt/lampp is the location where XAMPP files are kept. You will have to substitute the path to your XAMPP in the above command.

Uninstall XAMPP From your Machine

To uninstall XAMPP just type in this command

#rm -rf /opt/lampp


Better Solution for Filtering Bad Words in PHP


Hits: 1837  

I was searching for filtering Bad Words from my site……

I have visited so many links on google but…. 🙁

Here is my simple logic for filtering Bad Words from site or any search engine

First you have to make a txt file “badwords.txt” or you can search from google

Google Keyword: badwords + filetype:txt

Copy “badwords.txt” to your site and use below code for removing these words from site…..

<?php

// here file_get_contents() used for getting $badwords as a string

$badwords = strtolower(file_get_contents(“badwords.txt”));

// here $q is string used for checking against badwords

$pos = strpos($badwords, strtolower($q));

if ($pos !== false)
{

if(strstr($badwords, strtolower($q)) || strchr($badwords, strtolower($q)))
die(‘Website has blocked unwanted contents…. please try for legal keywords!’);
}

?>

Enjoy with svnlabs.com 🙂