XAMPP-PHP-MYSQL ancient code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

XAMPP-PHP-MYSQL ancient code

Postby lunaticbit » 09. April 2015 16:52

Dear friends. Long long time ago I started my voyage trying to learn web pages cpding, but I had problems that are not concerng anyone, but me (c' est la vie) Returning frompast versins (1.6 - 1.9) I encounterd a nw environmen from the one i left in pthe past. Trying to rsolve problms regarding past code I' ve been told that things were changed and that I have to start from scratch, snce no compatibility backwards has been provided. My aim is to find a way to open a blob field stored fieldin a mysql table in a new page. There were three parts in the old code.

Calling Page:

................
<?php
$db = mysql_connect("localhost", "root", "r00t");
mysql_select_db("alpha", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
................
echo "<td align=\"center\">";
// echo "<a href = \"content.php?id=$id\"</a>";
.................
?>

Dispplay Page:

<?php
$my_id = $_GET['my_id'];

if ($id_files)

if ($my_id)
{

include "open_db.inc";
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
}
?>
And the Module "open_db.inc

$db = mysql_connect("localhost", "binary_user", "binary_password");
mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
Of course if things have been dramaticaly chaged then the blob files stored in the table would be erroneous, but I must first to find a way to oen/savee frst. But this is an other story to tell after solving this problem.
Pls help a time traveller from the past!
I followed Larry Ullman's third edition of PHP mySQL Web Programming in the past..
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: XAMPP-PHP-MYSQL ancient code

Postby Altrea » 09. April 2015 20:50

Hi,

Start by replacing mysql with mysqli.
Good youtube tutorial on mysqli is here: https://www.youtube.com/watch?v=BEbKji_ ... EOVIO26R_o

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: XAMPP-PHP-MYSQL ancient code

Postby Nobbie » 09. April 2015 21:07

lunaticbit wrote:Pls help a time traveller from the past!


Sorry, but i cannot find any concrete question or problem. First of all: it is WRONG, that everything has changed, this is quite nonsense. There may be slight changes here or there, but BY FAR not "time traveller" or similar nonsense.

Where do you encounter concrete, real problems, where do you receive error messages and similar and what do these error messages tell you? I cannot help on that "story" about time traveller, please provide a real problem.

lunaticbit wrote:Of course if things have been dramaticaly chaged then the blob files stored in the table would be erroneous, but I must first to find a way to oen/savee frst. But this is an other story to tell after solving this problem.


No and no! Seems you are going for a "solution" to a problem, which does not exist. We dont provide blindfolded solutions, we solve problems. Ok?!
Nobbie
 
Posts: 8760
Joined: 09. March 2008 13:04

Re: XAMPP-PHP-MYSQL ancient code

Postby lunaticbit » 10. April 2015 14:35

Hey friend! Thank you for your time.
Replace mysql with mysqli in which specific partof the existing code? I'm trying to avoid general replacementNT in all parts of all modules to start understaining my leaks. As I've been toled from other guys the enviroment is totaly new. Try to understand my behavior. Bye bye and thanks!
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: XAMPP-PHP-MYSQL ancient code

Postby Nobbie » 10. April 2015 15:41

lunaticbit wrote:As I've been toled from other guys the enviroment is totaly new.


Then you should aks these other guys to tell you, what they mean and what is new. There is of course a (relatively) new API mysqli, but the mysql API is still supported and i cannot find any problem with your code. Therefore ask your guys whats is wrong with that. I cannot answer to that, as i dont agree.
Nobbie
 
Posts: 8760
Joined: 09. March 2008 13:04

Re: XAMPP-PHP-MYSQL ancient code

Postby Altrea » 10. April 2015 17:44

lunaticbit wrote:Replace mysql with mysqli in which specific partof the existing code?

Every mysql_* function needs to be replacd if you want to be sure your code will work with PHP 7 too.
Your code seems to require register_globals which is no longer existent in PHP, you should fix that too (googleing register_globals should bring you some ressources to read)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: XAMPP-PHP-MYSQL ancient code

Postby lunaticbit » 16. April 2015 15:21

Dear friend,
I spent my time trying to folow the propose youtube vids, trying to complete my knowlege, so I found somrthing appropriate, accordind to my skills, that could be used for my aim. So:

Code: Select all
<?php   
    //select data from the the files
    //@param int $id
    // @return array contains mime type and BLOB data

    $id = 1;
   public function selectBlob($id)
   {
      $sql = "SELECT type, data FROM myfiles WHERE id = :id";

      $stmt = $this->conn->prepare($sql);
      $stmt->execute(array(":id" => $id));
      $stmt->bindColumn(1, $type);
      $stmt->bindColumn(2, $data, PDO::PARAM_LOB);

      $stmt->fetch(PDO::FETCH_BOUND);

      return array("type" => $type,
            "data" => $data);

   }

   //close the database connection/
   //public function __destruct()
   //{
      // close the database connection
      //$this->conn = null;
   //}
//}
?>


Which drives me to the error:
Code: Select all

Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\xampp\htdocs\nictest\matakias.php on line 7



Any suggestion? Or how can I deal with an other way the old $_GET['id']; statement? in order to continue...
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: XAMPP-PHP-MYSQL ancient code

Postby Altrea » 16. April 2015 17:46

public is a setting for visibility of a PHP class method.
You can not use this for classless functions, visibility is useless here.

Read more about classes and objects here: http://php.net/manual/en/language.oop5.php
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: XAMPP-PHP-MYSQL ancient code

Postby lunaticbit » 20. April 2015 19:40

Sorry there wwere an errors concerning my former code.

<?php

$db = mysql_connect("localhost", "root", "r00t");
mysql_select_db("alpha", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");

$id =$_GET['id'];

if ($id)
{
//include "open_db.inc";
//$db = mysql_connect("localhost", "binary_user", "binary_password");
$db = mysql_connect("localhost", "root", "r00t")
//mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$sql = "SELECT bin_data, filetype, filename, filesize FROM myfiles WHERE id_files=$id"; // line 14
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
}
exit;
?>


The correct one returns, in the new environment, the error:

Parse error: syntax error, unexpected '$sql' (T_VARIABLE) in C:\xampp\htdocs\nictest\view.php on line 14

any idea what to replace to make it functional?
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: XAMPP-PHP-MYSQL ancient code

Postby Altrea » 20. April 2015 19:45

missing semicolon in line 12
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: XAMPP-PHP-MYSQL ancient code

Postby Nobbie » 20. April 2015 20:57

lunaticbit wrote: $db = mysql_connect("localhost", "root", "r00t")
//mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$sql = "SELECT bin_data, filetype, filename, filesize FROM myfiles WHERE id_files=$id"; // line 14


As you can see - no sorry - as you *SHOULD* see, there is a fatal syntax error on the mysql_connect() line, it is a missing semicolon.

This is simply a severe syntax error and it always has been a severe syntax error, therefore i do not believe anything about your crazy "time traveller" story, you simply like to have us to debug your faulty code, which has been faulty ever before.

Honestly, i dont like that anyway. Do you feel well by misusing this forum for your personal needs?
Nobbie
 
Posts: 8760
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: Altrea and 50 guests