Create .sql file for php script

Ok this may sound stupid but i’m trying to fix this php script and there’s no .sql file for the database so i’m trying to look at the code to see if i can figure out what the table and everything are suppose to be… so the question is is there a better/easier way to do it or am i outta luck and gotta do it by hand?

Thanks Snoop

You can produce a .sql file using a database management tool like phpmyadmin or you can do it using a low-level command line command.

Thanks phpdr i’ll check that out you probally saved me alot of headaches lol thought i was gonna have to do it all manually lol

Thanks Snoop

My reply was based on the above and that your statement means you just need the .sql file for troubleshooting information. If your statement actually means that you don’t have a database at all, and you are not actually trying to fix a php script, but to recreate the database design, then yes, you will need to go through the script to find the table, column, and data types needed. That then begs the question of how you have a php script without the corresponding database.

1 Like

I agree with phdr here as well…

If no database or myphpadmin or something to check out/view and export from…

This is going to be a painful task IMO…

and maybe not even possible? There could be many cols that are there/not used in the PHP script?

Thanks phpdr and whispers heres what happened i downloaded a script frome some site can’t remember where so i extracted it and there was no sql file with the script at all, I am trying to fix the script and yes i’m trying to recreate the db sql file… there was no db sql file and i went to the site in the readme but the site doesn’t exist no more i was gonna try to email the author i may still try to… but most of the times i try they never answer me…

I did fix a few things but here is the errors i’m still getting

Notice : Undefined variable: HTTP_SERVER_VARS in C:\UwAmp\www\phpstatus\includes\Template.php on line 16

Notice : Undefined variable: HTTP_SERVER_VARS in C:\UwAmp\www\phpstatus\includes\functions.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘-_groups’ at line 1

I can’t figure that error out i have checked all the files and found it in only acouple of files not sure what it’s suppose to be doing

Heres the php code giving me problems

if(preg_match("/Template.php/i",$HTTP_SERVER_VARS[‘PHP_SELF’])) {
header(“Location: …/index.php”);
exit();
}

$HTTP_SERVER_VARS seems to be the problem

I can Post what i have for the sql so far if that will help lol

BTW the name of the script is PHPStatus Server Status

Thanks Snoop

HTTP_SERVER_VARS

is most likely the DB credentials needed to connect/access your database…

update:
Seems like a VERY (very) old way of defining variables in PHP?

Perhaps just trying upgrading to use: $_SERVER instead?

For example, if your code uses a line like this:

parse_str($HTTP_SERVER_VARS["QUERY_STRING"]);

It should be replaced with:

parse_str($_SERVER["QUERY_STRING"]);

Man your good it got rid of the 2 errors
Notice : Undefined variable: HTTP_SERVER_VARS in C:\UwAmp\www\phpstatus\includes\Template.php on line 16

Notice : Undefined variable: HTTP_SERVER_VARS in C:\UwAmp\www\phpstatus\includes\functions.php on line 16

now all i’m getting is this error which i have no idea were it’s at

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘-_groups’ at line 1

Trying to locate that one now

Thanks Snoop

FInd where the text: ‘-_groups’ is located…

and post the full context of its usage.

Some code (somewhere) is attempting to make a SQL call of some sort…no?

Here is the one file in phpstatus\admin\add_group.php

the _groups is on lines 36 & 58

  1. $sql = "SELECT name FROM “.$prefix.”_groups WHERE

  2. name=’$HTTP_POST_VARS[name]’"; $result = $db->query($sql);

  3. $num = $db->num($result);

  4. $sql = “INSERT INTO “.$prefix.”_groups (name, ports) VALUES (’$HTTP_POST_VARS[name]’, ‘$ports’)”;

  5. $result = $db->query($sql);

Thanks Snoop

Looks like:

_groups

Is part of a TABLE name .

Also looks like you have some of the OLD Server vars in there as well…

not clear where $prefix is coming from…

This also doesnt look like PDO type of syntax… this is very old script apparently… I would update things to use PDO.

thanks whispers yeah _group is a db table i believe… the $prefix is the db prefix. yeah i thinks its an older script i’m going to try to do what you said and update it to use pdo… i’ll keep this post updated

thanks for all the help everyone :smile:

Thanks Snoop

Is your server still running PHP 5.x?

if so… perhaps try working out the variable issues… to ensure the scrip is working… then convert/update to use PDO for parameterized queries…etc

well yeah if you mean php i’m running 5.6.40 right now… i’m having problems with the pdo stuff lol i found a pdo db script i believe its using pdo mysql but i’m trying to modify the pdo to match the original db script… change the function names ect…

heres the original db script

heres the pdo db script

can u look at the pdo one and tell me if i can make that work for what i need to do?

Thanks Snoop

Well that was kinda my point…

get the OLD version working… so you know all old/depreciated code is gone… and all variables are there/working…etc…

THEN updating to PDO would be a lot simpler… knowing any bugs/errors are from the migration to PDO… and not some older, underlying error from this old script.

This is some DB class?? Not a simple connection select/insert type of routine…

Yeah that’s what i’m doing i all most fixed all of them except one and i still can’t figure out were it is heres the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘-_groups’ at line 1

i searched all the files for _groups in them and found 11 files with _groups in them so i’m going through all of them again to try to find
i’ll let ya know what i find…

Thanks Snoop

Based on the ‘near…’ text in the error message, $prefix contains just a - (dash) or ends in a -. This character is not permitted in a plain identifier. Since the posted line of code using $prefix doesn’t contain the identifier quote character ` (back-tick), the simplest fix would be to make sure that $prefix only contains ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore).

Thanks so much for helping me i believe i got all the other errors fixed but all i’m getting now is this error…

Table ‘phpstatus.__groups’ doesn’t exist

i wanted to ask do u think it’d be ok to totally remove the prefix stuff
because that’s what’s causing the problems i think

Thanks Snoop

Ok i got all the errors with the script now i’m getting this error

Table ‘phpstatus.__groups’ doesn’t exist

here is what i have figured out on the sql file i tried to rebuild it from looking at the files in the script i may have missed some not sure…

i still think that prefox is messing it up some how so i may try to remove the proefix and see what i get…

Thanks Snoop

does that table exist? with the period? same name matches table in your current DB?

Sponsor our Newsletter | Privacy Policy | Terms of Service