sábado, 7 de febrero de 2015

remove space and whitespace from a variable

For just spaces, use str_replace:
$string = str_replace(' ', '', $string);




For all whitespace, use preg_replace:

$string = preg_replace('/\s+/', '', $string); 

http://stackoverflow.com/questions/2109325/how-to-strip-all-spaces-out-of-a-string-in-php 




<?php
function string_to_filename($word) {
    $tmp preg_replace('/^\W+|\W+$/'''$word); // remove all non-alphanumeric chars at begin & end of string
    $tmp preg_replace('/\s+/''_'$tmp); // compress internal whitespace and replace with _
    return strtolower(preg_replace('/\W-/'''$tmp)); // remove all non-alphanumeric chars except _ and -}?>

mySQL select IN range


Is it possible to define a range for the IN part of the query, something like this
SELECT job FROM mytable WHERE id IN (10..15);
Instead of
SELECT job FROM mytable WHERE id IN (10,11,12,13,14,15);
shareimprove this question

1 Answer

up vote 28 down vote accepted
You can't, but you can use BETWEEN
SELECT job FROM mytable WHERE id BETWEEN 10 AND 15
shareimprove this answer

viernes, 21 de noviembre de 2014

Como reparar una tabla MYSQL

En este caso vamos a reparar la tabla  kvstore en la base de datos asterisk.
mysqlcheck asterisk kvstore --auto-repair -p

 mysqlcheck -u root -p --auto-repair -c -o --all-databases
http://www.thegeekstuff.com/2011/12/mysqlcheck/

miércoles, 19 de noviembre de 2014

Script para extraer cantidad de tiempo transcurrido

<?php
require ("./library/conect.php");

$result = mysql_query("SELECT timediff(now(),date) AS time,date,phone,advnumber FROM `leads` where `campaign` ='o65' order by date asc");
echo "Total de records ".mysql_num_rows($result );
echo "<table border='1'>
<tr>
<th>ID</th>
<th>STATE</th>
<th>TIME</th>
<th>TIME</th>
<th>ELIMINAR</th>
</tr>";
   while($row = mysql_fetch_array($result))
    {
  echo "<tr>";
 echo "<td>" . $row['phone']."</td>";
  echo "<td>" . $row['advnumber'] . "</td>";
  echo "<td>" .  $row['time'] . "</td>";
  echo "<td>" .  substr($row['time'],-5,2). "</td>";  //extrayendo solo los minutos transcurridos
echo "<td><a href=?ID=$row[recordid]>" ."ELIMINAR" . "</td></a>";
  echo "</tr>";
$GLOBALS['b']= $row['time'];     // declaramos la Variable global para tener acceso en todo el script
}

echo "</table>";
echo $b;
mysqli_close($con);
?>

sábado, 15 de noviembre de 2014

Backup and Restore MySQL Database Using mysqldump

 
mysqldump -d -h localhost -u root -p1233 insurance > insurance.sql
mysqldump -d -h localhost -u root -p1233 asterisk> asterisk.sql



How To Restore MySQL database


1. Restore a database

In this example, to restore the sugarcrm database, execute mysql with < as shown below. When you are restoring the dumpfilename.sql on a remote database, make sure to create the sugarcrm database before you can perform the restore.
# mysql -u root -ptmppassword

mysql> create database sugarcrm;
Query OK, 1 row affected (0.02 sec)

# mysql -u root -ptmppassword sugarcrm < /tmp/sugarcrm.sql

# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
 
 


http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/

viernes, 7 de noviembre de 2014

Activando el short_open_tag = On

Si queremos que nuestros script sean reconocidos  <? ?> y no tener que escribirlo de la siguiente manera <?php ?>


Editar los arhicos php.ini
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
activar el short_open_tag
short_open_tag = On
/etc/init.d/apache2 restart