MySQL Archives

How to use MySQL REPLACE function

Here’s a MySQL query fuction that’s easy to forget about: REPLACE. Let’s say I have a bunch of records in a field with http://www and want to quickly change all to http://. Here’s the syntax to update:

UPDATE tdurl_1 SET URL = REPLACE(URL, ‘http://www.tdurl.com/’,’http://tdurl.com/’);

Open source phpMyEdit

phpMyEdit:
generates PHP code for displaying/editing MySQL tables in HTML. All you need to do is to write a simple calling program (a utility to do this is included). It includes a huge set of table manipulation functions (record addition, change, view, copy, and removal), table sorting, filtering, table lookups, and more.
Download (gz).

Setting up a new Wordpress blog

This guide assumes you have already downloaded and unzipped/untarred the most current Wordpress version. These instructions do not cover the multi-user WP version.
Steps for setting up a new Wordpress (WP) blog:
1. Database created? Create a MySQL database for the domain.
Note: If you have more than one WP blog installed in the same database then open […]

MySQL 5.0 production version now available, includes subqueries

MySQL 5.0 is now ready for use on production servers touting the following features: stored procedures and SQL functions, triggers, views, cursors, information schema, XA distributed transactions, SQL mode, new federated and archive storage engines, new migration toolkit, instance manager, updated connectors, visual tools and more.
Complete list of changes in 5.0.x production.
The functionality I’m excited […]

ARSC v3.0.2 RC 2 free chat

Looking to add chat to your server? Don’t want to mess with java and IRC? Want to try a PHP/MySQL solution? ARSC could be for you.

From the 4-step installation from INSTALL docs:
- Create a MySQL database
- Provide the hostname, username, password, and database
name to allow ARSC to connect to your MySQL Server
- […]

Query results within last X days

Sometimes it is necessary to query data from the last 7 days. Here’s how to create a dynamic query inside a script using PHP / MySQL to return a list of users who last visited within X number of days (7 by default):

<?php
$now = time(); // this is the current UNIX timestamp for the server
$days […]

Changing databases inside code

To change MySQL databases within code use the mysql_select_db() function like this:

<?php
 mysql_select_db(‘db_2′, $mysql_link);
$query = “SELECT username from user where userid = ‘$user_id’”;
$result = mysql_query($query,$mysql_link);
        if(mysql_num_rows($result)) {
                $row = mysql_fetch_row($result);
                $username = $row[0];
        }
mysql_select_db(‘db_1′, $mysql_link);
?>

This code […]

How to join an ID list using IN MySQL function

How to create a query list of ID numbers using join from an $array and put into a string that can be used in a MySQL query:

$id_numbers = array(1,6,14,32,84,27,49,77);
$complist = join(”,”, $id_numbers);
$query = “SELECT id from tablename WHERE id IN($complist)”;