Fout in script na upgrade
Ik gebruik een script om een database te vullen.
Dit heeft altijd gewerkt tot dat ik van libapache2-mod-php5.2 naar libapache2-mod-php5.4 ben gegaan.
Nu krijg ik als ik een file wil uploaden een error 500 en zie in de logfile:
PHP Fatal error: Call-time pass-by-reference has been removed in readlog.php on line 18
Readlog is het stuk script dat de file inleest en weg schrijft in de database.
Ik zie niets gek op op regel 18
Ik heb geen idee waar te zoeken.
Een stuk van het srcipt:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
include 'dbinc.php';
include 'error.inc';
// Function to read one line of QSO data from the Cabrillo file and parse according to the contest type
// Parameters:
// $contest_type - Cabrillo contest type (determines the number of columns in the QSO data)
// $s - the QSO: line from the Cabrillo file
// &$qso_data - array to put parsed data into
function readCabrilloQSO ($contest_type, $s, &$qso_data)
{
switch ($contest_type)
{
case "ARRL-VHF-SEP":
// This Cabrillo format has 9 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy);
break;
=====================
// Function to read a Cabrillo file and insert each QSO into the database
// Parameters:
// $file - file pointer of Cabrillo file being read
// $qso_count - (global) number of QSOs read
// $connection - Database connection
// $dxcallsign - FK to logbook
function processCabrilloFile ($file, &$qso_count, $connection, $dxcallsign)
{
// Initialise the array
$qso_data = array ('freq' => '',
'mode' => '',
'call' => '');
// Read the Cabrillo file until we reach the "CONTEST:" tag
while (fscanf ($file,"%s %s",&$tag, &$value))
{
if (!strcasecmp($tag, "CONTEST:"))
{
// Read the contest type so that we can parse the file
$contest_type = $value;
echo "<p>Cabrillo Contest type is $contest_type <P>\n";
break;
}
else
// Continue until the CONTEST: tag is reached
continue;
}
// Keep a count of the number of QSOs added to the database
$qso_count = 0;
// Read each line of the log file
while ($s = fgets ($file,1024))
{
$line = explode (' ', $s);
// Skip Cabrillo header lines
if (!strcasecmp($line[0], "QSO:"))
{
// Read one line of QSO data from the Cabrillo file
readCabrilloQSO ($contest_type, $s, &$qso_data);
}
else
// Continue reading until the "QSO" tag
continue;
// Convert frequency to band
$band = convertFrequencyBand ($qso_data['freq']);
// Trap unknown bands error
if ($band == 0)
{
$freq = $qso_data['freq'];
echo "<P><EM>Error - Frequency to Band conversion failed - frequency: $freq</EM></P>\n";
echo "<P>No QSOs loaded\n";
echo "<p><A HREF=\"uploadlog.php\">Return to Log Upload Page</A>\n";
die();
}
// Cabrillo logs contain mode as "CW/PH/RY"
// Convert PH to SSB
if (!strcasecmp($qso_data['mode'],"PH"))
$qso_data['mode'] = 'SSB';
// Convert RY to DIG
if (!strcasecmp($qso_data['mode'],"RY"))
$qso_data['mode'] = 'DIG';
// Insert QSO into the database
$query = "INSERT INTO qsos SET id = 0, " .
"callsign = \"" . $qso_data['call'] . "\" , " .
"op_mode = \"" . $qso_data['mode'] . "\" , " .
"band = \"" . $band . "\" , " .
"fk_dxstn = \"" . $dxcallsign . "\" ";
if (!(@ mysql_query ($query, $connection)))
showerror();
$qso_count++;
}
}
include 'dbinc.php';
include 'error.inc';
// Function to read one line of QSO data from the Cabrillo file and parse according to the contest type
// Parameters:
// $contest_type - Cabrillo contest type (determines the number of columns in the QSO data)
// $s - the QSO: line from the Cabrillo file
// &$qso_data - array to put parsed data into
function readCabrilloQSO ($contest_type, $s, &$qso_data)
{
switch ($contest_type)
{
case "ARRL-VHF-SEP":
// This Cabrillo format has 9 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy);
break;
=====================
// Function to read a Cabrillo file and insert each QSO into the database
// Parameters:
// $file - file pointer of Cabrillo file being read
// $qso_count - (global) number of QSOs read
// $connection - Database connection
// $dxcallsign - FK to logbook
function processCabrilloFile ($file, &$qso_count, $connection, $dxcallsign)
{
// Initialise the array
$qso_data = array ('freq' => '',
'mode' => '',
'call' => '');
// Read the Cabrillo file until we reach the "CONTEST:" tag
while (fscanf ($file,"%s %s",&$tag, &$value))
{
if (!strcasecmp($tag, "CONTEST:"))
{
// Read the contest type so that we can parse the file
$contest_type = $value;
echo "<p>Cabrillo Contest type is $contest_type <P>\n";
break;
}
else
// Continue until the CONTEST: tag is reached
continue;
}
// Keep a count of the number of QSOs added to the database
$qso_count = 0;
// Read each line of the log file
while ($s = fgets ($file,1024))
{
$line = explode (' ', $s);
// Skip Cabrillo header lines
if (!strcasecmp($line[0], "QSO:"))
{
// Read one line of QSO data from the Cabrillo file
readCabrilloQSO ($contest_type, $s, &$qso_data);
}
else
// Continue reading until the "QSO" tag
continue;
// Convert frequency to band
$band = convertFrequencyBand ($qso_data['freq']);
// Trap unknown bands error
if ($band == 0)
{
$freq = $qso_data['freq'];
echo "<P><EM>Error - Frequency to Band conversion failed - frequency: $freq</EM></P>\n";
echo "<P>No QSOs loaded\n";
echo "<p><A HREF=\"uploadlog.php\">Return to Log Upload Page</A>\n";
die();
}
// Cabrillo logs contain mode as "CW/PH/RY"
// Convert PH to SSB
if (!strcasecmp($qso_data['mode'],"PH"))
$qso_data['mode'] = 'SSB';
// Convert RY to DIG
if (!strcasecmp($qso_data['mode'],"RY"))
$qso_data['mode'] = 'DIG';
// Insert QSO into the database
$query = "INSERT INTO qsos SET id = 0, " .
"callsign = \"" . $qso_data['call'] . "\" , " .
"op_mode = \"" . $qso_data['mode'] . "\" , " .
"band = \"" . $band . "\" , " .
"fk_dxstn = \"" . $dxcallsign . "\" ";
if (!(@ mysql_query ($query, $connection)))
showerror();
$qso_count++;
}
}
Gewijzigd op 01/06/2013 17:56:32 door Peter Prive
sscanf weghalen. Als ik de manual goed begrijp worden de referenties automatisch gebruikt en zal het zonder de & tekens dus werken.
Nogmaals, ik ben er niet 100% zeker van, maar zo interpreteer ik de foutmelding.
Zeker weten doe ik het niet, maar het lijkt erop dat je geen variabelen by reference kan opgeven, niet op die manier in elk geval. Met anderen woorden, je moet alle & tekens in de functie aanroep van Nogmaals, ik ben er niet 100% zeker van, maar zo interpreteer ik de foutmelding.
http://nl3.php.net/sscanf#example-4757 dan blijken daar ook geen "&" gebruikt te worden.
Ja inderdaad, als ik het volgende voorbeeld bekijk: Ik heb de & weggehaald, naar nu loopt hij vast op regel 228 (van de +470 regels)
Kennijk is er wel e.e.a. veranderd dat niet compatibel is tussen 5.2 en 5.4
Wil dat stukje script wel neerzetten, maar hoe voeg ik dat in zodat je netjes de regels ziet met nummer?
Tanks Peter
Ja die regelnummering kun je niet aanpassen. Kopiëer en plak gewoon een stuk of tien regels vóór regel 228 en een paar regels erna en zeg welke regel oorspronkelijk regel 228 was.
while (fscanf ($file,"%s %s",&$tag, &$value))
Tanks Peter
Wilde gok, hetzelfde probleem? Dus ook zelfde oplossing....?
Je heb gelijk. Even bezem langs alle & halen en het werkt
Bedankt