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 8359589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:11:28+00:00 2026-06-09T11:11:28+00:00

I wouldn’t want to talk too much, here is my code (I know it

  • 0

I wouldn’t want to talk too much, here is my code (I know it is not PDO, but it will once it can work). Almost everything working!!!

Now I am doing the logs and I am stuck! – UPDATE thanks to Michael some of it has fixed!

$statresult=mysql_query($statsql, $actconn) or die(mysql_error());

Optimize function too. This is not working with Multiple DB some reason…

The permission doesn’t want to be right I have looked hours and I can’t figure it out. A part from that everything works beautifully.

The code reads some rows from the real DB and moves them to the backupDB. But I want a cron job and email alert so I did an easy log (into a table) but it doesn’t want to work… I can’t even see any error log. Well: PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sites/stcticketing.org/public_html/back/asu1.php on line 34

<?php
// open db
$dbhost = 'localhost';
$actdbuser = 'user1';
$actdbpass = 'pass';

$bckdbuser = 'user2';
$bckdbpass = 'pass';

$actconn = mysql_connect($dbhost, $actdbuser, $actdbpass) or die ('act Error connecting to mysql');
$bckconn = mysql_connect($dbhost, $bckdbuser, $bckdbpass) or die (' back Error connecting to mysql');

$actdbname = '`web151-tevenyal`';
mysql_select_db($actdbname, $actconn);

$bckdbname = '`web151-bckproba`';
mysql_select_db($bckdbname, $bckconn);

//end opendb


//functions
function test($sqls, $states){
 if ($sqls=1){
   $resflag=1;
 }
 else {
   $resflag=0;
 }
 $statsql="INSERT INTO `web151-tevenyal`.`tex_bcklog` (`what`,`how`,`when`) VALUES ('$states',$resflag,CURDATE());";
 echo "<p>".$sqls."<br/>".$statsql."</p>"; 
 $statresult=mysql_query($statsql, $actconn) or die(mysql_error());
 echo "<p>".$states." - ".$resflag."</p>";
 $emaltext=$emailtext.$sqls;
}

function db_rows($db,$ord, $connectdb){
 $dbquery="SELECT azon FROM $db ORDER BY azon $ord LIMIT 1";
 $dbresult=mysql_query($dbquery, $connectdb);
 $row = mysql_fetch_array($dbresult);
 $dbrow = $row['azon'];
 return $dbrow;
}
// end of functions

//config information...
$acttable  = 'adat';
$today = date("yW_Hi");
$newdb = $bckdbname.".test_".$today;
test($permsql, "grant");
test(1, "backupstart");

//creating log table for backup results
$backtablesql="CREATE TABLE IF NOT EXISTS `tex_bcklog` ( `azon` int(11) NOT NULL AUTO_INCREMENT,`what` varchar(255) CHARACTER SET utf8 NOT NULL,  `how` varchar(255) CHARACTER SET utf8 NOT NULL,  `when` date NOT NULL,   PRIMARY KEY (`azon`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;" ;
//$backtableresult=mysql_query($backtablesql);



$firstact= db_rows($actdbname.".".$acttable,"asc", $actconn);
$lastact= db_rows($actdbname.".".$acttable,"desc", $actconn);
$upto=$firstact+25000;


if ($lastact-$firstact>50000) {

 //create a new table 
 $permsql="GRANT SELECT ON `$actdbuser`.* TO `$bckdbuser`@'%' ;";
 test($permsql, "grant");
 $perm = mysql_query($permsql, $bckconn) or die(mysql_error());

 $newdbsql="CREATE TABLE $newdb LIKE $actdbname.`$acttable`";
 test($newresult, "createdb");
 $newresult = mysql_query($newdbsql, $bckconn) or die(mysql_error());


 // copy all the data
 $query = "INSERT INTO $newdb SELECT * FROM $actdbname.$acttable WHERE $acttable.azon < $upto";
 test($query, "copyrows");
 $result = mysql_query($query) or die(mysql_error());

 // so what has happened...
 $delquery = "DELETE FROM $actdbname.$acttable WHERE $actdbname.$acttable.azon < $upto";
 test($delquery, "deleterows");
 $delresult = mysql_query($delquery, $actconn);

 // then tidy up everything:)
 $res = mysql_query('SHOW TABLE STATUS WHERE Data_free / Data_length > 0.1 AND Data_free >  102400', $actconn);
 while($optrow = mysql_fetch_assoc($res)) {
   mysql_query('OPTIMIZE TABLE ' . $optrow['Name']);
  }
 }
 else {
  test(0, "nothing");
 }

 // send an email to confirm what's happened - thanks:)

 // close db 
 mysql_close($actconn);
 mysql_close($bckconn);
 ?>

Please fix it first and then comment any PDO unless the solution itself:) Any help would be greatly appreciated!

  • 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-06-09T11:11:30+00:00Added an answer on June 9, 2026 at 11:11 am

    Inside the function that is failing (it is done correctly in the other function db_rows()), your database resource link variables are out of scope. Pass them to the functions as parameters:

    For example, pass one in as $connection here:

    function test($sqls, $states, $connection){
     if ($sqls=1){
       $resflag=1;
     }
     else {
       $resflag=0;
     }
     $statsql="INSERT INTO `web151-tevenyal`.`tex_bcklog` (`what`,`how`,`when`) VALUES ('$states',$resflag,CURDATE());";
     echo "<p>".$sqls."<br/>".$statsql."</p>"; 
     $statresult=mysql_query($statsql, $connection) or die(mysql_error());
     echo "<p>".$states." - ".$resflag."</p>";
     $emaltext=$emailtext.$sqls;
    }
    

    Then call the function with the correct connection as in:

    test($permsql, "grant", $actconn);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I figured this wouldn't be too difficult to do, but I can't seem to
I know it probably wouldn't make much sense to do it as usually it's
Can anybody tell me why the following line of code wouldn't be a legitimate
I know it wouldn't be exactly equivalent to $this, but is there a way
So I wouldn't be stupid enough to ask this in general, but here's the
I've come so far (but you wouldn't know it). Struggling through my art website.
This is clearly not appears like it wouldn't be a best practice. Can someone
I wouldn't normally paste an image, I would provide the code as text, but
Why wouldn't this work? I've reviewed my code several times and just can't find
I thought I wouldn't need to ask this but I am not having any

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.