Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6344175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:35:06+00:00 2026-05-24T20:35:06+00:00

I have experienced about two times that mysql database crashes and it can not

  • 0

I have experienced about two times that mysql database crashes and it can not be connected for a long time and I always have to contact the hosting service to reactivate it…for some reason. So I want to create a mechanism to resolve this problem whit the backup file. heres the code:

<?php
$query = //some source
$db_user = "data_search";
$db_password = "password";
$database = "data_search";
$backupfile = '/data_search.sql';  
$db_table = "words";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
mysql_query("set names 'utf8'");

if ($db) {
    $result = mysql_query("
        SELECT
            *
        FROM
            $db_table
        WHERE
            word = '$query'
        LIMIT
            0 , 1
    ");
} else {
    $result = mysql_query("
        LOAD DATA INFILE
            '$backupfile'
        FROM
            '$db_table'
        WHERE
            word = '$query'
        LIMIT
            0 , 1
    ");  
}

$num = mysql_numrows($result); 
$i = 0;
while ($i < $num) {
    $word = mysql_result($result,$i,"word");
    echo $word;
    $i++;
}

Now this is only a sample and im 100% accurate that the error is in the backup query($result). Basically what I want is to: if it cant connect to use the backup file. This returns $num = 0; Can someone help me to execute this code? What mysql_query() am I looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:35:07+00:00Added an answer on May 24, 2026 at 8:35 pm

    Use mysqldump instead. You may start it from PHP:

    /* get mysql database as gzipped backup file;
     * be aware, that the DB-password is stored in the ~/.bash_history,
     * if you include it in the program-call;
     */
    shell_exec('mysqldump --host=DB_HOST --user=DB_USER --password=DB_PASSWORD --databases DB_NAME --skip-triggers --compact --no-create-info | gzip -9 > BACKUP_FILENAME-`date +%Y-%m-%d_%Hh%Mm%Ss`.sql.gz')
    

    Or just do that via a shell-script:

    # !/bin/bash
    
    REMOTE_DB_USER="my-database-user"
    REMOTE_DB_PASSWORD="my-database-password"
    REMOTE_DATABASE="my-database-name"
    LOCAL_BACKUP_DIRECTORY="~/backup/dumps"
    CURRENT_TIMESTAMP=`date +%Y-%m-%d_%Hh%Mm%Ss`
    
    # switch to local backup directory
    echo "change dir";
    cd $LOCAL_BACKUP_DIRECTORY
    
    # dump whole remote database to gzipped file
    echo "dump db to local"
    /usr/bin/mysqldump --user=$REMOTE_DB_USER --password=$REMOTE_DB_PASSWORD --host=127.0.0.1 --port=3306 $REMOTE_DATABASE | gzip -9 > dump-$CURRENT_TIMESTAMP.sql.gz
    
    echo "finished"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all: I am not an experienced ClearCase user, but I have lots
On the advice of a more experienced developer, I have always coded my web
I have tried on two different machines, and tried the download several times, but
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
Anyone have any experience evaluating BlazeDS and GraniteDS? I'm curious about which is better
I know this isn't strictly a programming question but y'all must have experienced this.
I've experienced rather strange behavior of JSTL forEach tag. I have some bean called
Most of experienced programmer knows data alignment is important for program's performance. I have
I have been asked to look into FileMaker for creating a pretty simple database
There have been many debates about this topic already here, but none of them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.